php-general Digest 1 Dec 2007 21:29:52 -0000 Issue 5158
Topics (messages 265348 through 265371):
sprintf() oddness
265348 by: Christoph Boget
265349 by: Per Jessen
265350 by: Jochem Maas
265360 by: Per Jessen
265361 by: tedd
Re: Join question
265351 by: Jochem Maas
265352 by: Jochem Maas
265353 by: Jochem Maas
265355 by: tedd
265367 by: Daniel Brown
PHP Celebrity Death Match ...
265354 by: Jochem Maas
265356 by: tedd
265368 by: Jay Blanchard
265369 by: Daniel Brown
Re: PHP/AJAX File Drag&Drop
265357 by: Rafael
Re: Quick question on data formatting
265358 by: tedd
Image functions: date?
265359 by: Dotan Cohen
265362 by: Dotan Cohen
265363 by: Dotan Cohen
Re: Join question [solved]
265364 by: Daniel Brown
problems accesing an object via globals
265365 by: julian
265366 by: julian
Re: how do i get a printout of original multipart post data
265370 by: Olav Mørkrid
265371 by: Nathan Nobbe
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
Why does
sprintf( '%.03f', 0.15250000 )
return 0.152 while
sprintf( '%.03f', 0.15750000 )
return 0.158?
The 4th significant digit in both cases is '5' but in the first case, it's
rounded down but in the second case it is rounded up. Is sprintf() basing
it's decision on the value of the 3rd significant digit? If so, why?
Shouldn't rounding decisions be based on subsequent digits and not preceding
ones?
I am using PHP 4.3.11
thnx,
Christoph
--- End Message ---
--- Begin Message ---
Christoph Boget wrote:
> Why does
>
> sprintf( '%.03f', 0.15250000 )
> return 0.152 while
> sprintf( '%.03f', 0.15750000 )
> return 0.158?
>
> I am using PHP 4.3.11
I see the same behaviour in 5.2.4
/Per Jessen, Zürich
--- End Message ---
--- Begin Message ---
Per Jessen wrote:
> Christoph Boget wrote:
>
>> Why does
>>
>> sprintf( '%.03f', 0.15250000 )
>> return 0.152 while
>> sprintf( '%.03f', 0.15750000 )
>> return 0.158?
most likely it's an artifact of the fact that
the binary representations of those floating point
values are not exact e.g. 0.1575 is represented
in binary as something like 0.157500001
something like that.
>>
>> I am using PHP 4.3.11
>
> I see the same behaviour in 5.2.4
>
>
> /Per Jessen, Zürich
>
--- End Message ---
--- Begin Message ---
Jochem Maas wrote:
> Per Jessen wrote:
>> Christoph Boget wrote:
>>
>>> Why does
>>>
>>> sprintf( '%.03f', 0.15250000 )
>>> return 0.152 while
>>> sprintf( '%.03f', 0.15750000 )
>>> return 0.158?
>
> most likely it's an artifact of the fact that
> the binary representations of those floating point
> values are not exact e.g. 0.1575 is represented
> in binary as something like 0.157500001
>
> something like that.
I just tried it in plain C - same result.
/Per Jessen, Zürich
--- End Message ---
--- Begin Message ---
At 7:10 AM -0500 12/1/07, Christoph Boget wrote:
Why does
sprintf( '%.03f', 0.15250000 )
return 0.152 while
sprintf( '%.03f', 0.15750000 )
return 0.158?
The 4th significant digit in both cases is '5' but in the first case, it's
rounded down but in the second case it is rounded up. Is sprintf() basing
it's decision on the value of the 3rd significant digit? If so, why?
Shouldn't rounding decisions be based on subsequent digits and not preceding
ones?
I am using PHP 4.3.11
thnx,
Christoph
Actually, it's more accurate to use the preceding digit to determine
rounding. What you describe is "if even then round down else round
up". That's more accurate than always rounding up or always rounding
down.
Please follow:
When the digit is zero, no rounding takes place.
When the digit is 1 - 4, round down.
When the digit is 6 - 9, round up.
Fine up to there -- but, if you always round up or down for 5, then
you are introducing bias.
So, if you use the even/odd value of the preceding digit to determine
which way to round for 5, then it's more accurate.
However, no rounding is accurate -- it's just that some methods are
less error prone.
Here's a demo:
http://www.webbytedd.com/bbb/rounding/
My rounding method doesn't always win against php's round(), but it
wins more times than not. Plus, it takes a lot of rounding to
introduce the bias I found and thus for most applications using the
round() function (always round down) will suffice.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
Crayon Shin Chan wrote:
> On Friday 30 November 2007, Jochem Maas wrote:
>
...
>
> So let me get this straight, only paid up members of the old boys club are
> allowed to make off-topic posts? The rest can lump it?
if by the rest you mean you, then yes, absolutely, please crawl back under the
rock you came from and f***ing staying there you silly little troll.
>
>> besides which it's rather pointless telling someone to go elsewhere for
>> help when they already got the help and posted that they had solved the
>> problem.
>
> That's for future reference.
>
--- End Message ---
--- Begin Message ---
Jay Blanchard wrote:
> [snip]
> If you try you can probably make a connection from php to everything
> under
> the sun, doesn't mean everything under the sun is an appropriate topic
> for this list.
> [/snip]
>
> The Oracle of PHP - 6 Degrees of Separation
>
> I joined PHP to Oracle, Kevin Bacon and temperature all in one shot.
>
> Tedd, what did you want to know about joins?
:-) u made me laugh, makes me want grab a box of crayons and draw you a pretty
picture.
>
--- End Message ---
--- Begin Message ---
chris smith wrote:
> On Dec 1, 2007 3:53 PM, Crayon Shin Chan <[EMAIL PROTECTED]> wrote:
>> On Saturday 01 December 2007, tedd wrote:
>>> At 10:21 AM +0800 11/30/07, Crayon Shin Chan wrote:
>>>> On Friday 30 November 2007, tedd wrote:
>>>>> I'm trying to understand joins,
>>>> Ask on a database related list.
>>> Really?
>> Really.
>
> Considering the rest of the off-topic questions that regularly get
> asked on this list it's a bit much to single out this one particular
> post.
>
> javascript, css, html - none is directly related to php but all still
> get asked here (and 99% of the time answered) - I don't know why
> you're making such a big deal about this particular post and haven't
> kicked up a fuss about the rest in the past.
you never with trolls. maybe it's because trolls eat Rocks[tm] and Tedd
used to program in Rocks[tm] (which I presume left trolls with a shortage
or something)
>
--- End Message ---
--- Begin Message ---
At 11:07 PM -0600 11/30/07, Jay Blanchard wrote:
The Oracle of PHP - 6 Degrees of Separation
I joined PHP to Oracle, Kevin Bacon and temperature all in one shot.
Sounds like an omelette. :-)
Tedd, what did you want to know about joins?
I think I got it -- at least for the problem that was confronting me.
Unfortunately, I was working on an older version of MySQL with
limited functionality. But, trial and error paid off and I learned a
lot in the process.
Thanks for your support.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
On Nov 30, 2007 11:53 PM, Crayon Shin Chan
<[EMAIL PROTECTED]> wrote:
> You ought to know by now that there is the php-db list. Even so your
> question doesn't belong even there because it has zilch to do with php,
> but it is still slightly more appropriate to post there than here.
Put on your flame-retardant suit, umm.... flame retard.
Over the course of several months, it's rare that I see you do
anything but bitch and complain. I've never seen anyone have their
period for a full year until I started reading your junk. You slap
people for top-posting, complain about things being off-topic,
criticize the newbies rather than educate, and overall make everyone
wish that email had an ignore button, you ridiculous anime-obsessed
child.
This list is PHP-centric, yes.... but it's still a community.
Hell, I think I speak more with some of the people on this list than I
do my own pre-wife some days. In fact, I know I do! There are a
great deal of highly-intelligent people on this list, so why not take
advantage of that resource?
Now, do you want to see something interesting? Go to Google and
search for your email address. I found 81 results, most of which are
duplicates.
Now search for just the name "parasane". It's a name I made up
myself (registered, Copyrighted, et cetera), so it's all my stuff. I
see 4,530 results in a wide variety of areas.
Then feel free to search for "Tedd Sperling" in quotes so that you
search for that exact name. Tedd's made his mark on at least the
1,930 results of which Google keeps track.
So until you've been around enough to truly earn your right to
tell someone far more accomplished than yourself to seek help
elsewhere, do us all a favor and keep your God damned mouth shut.
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.
--- End Message ---
--- Begin Message ---
Brad v. Crayon.
any good animators among us up to the challenge?
--- End Message ---
--- Begin Message ---
At 2:19 PM +0100 12/1/07, Jochem Maas wrote:
Brad v. Crayon.
any good animators among us up to the challenge?
I'm not good, but I'm childish enough.
http://www.webbytedd.com/aa/brain-v-brain/
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
[snip]
Brad v. Crayon.
[/snip]
A very small nail up against a small colored wax cylinder is what came
to mind, and I laughed a great deal at the animation in my head.
--- End Message ---
--- Begin Message ---
On Dec 1, 2007 1:10 PM, Jay Blanchard <[EMAIL PROTECTED]> wrote:
> [snip]
> Brad v. Crayon.
> [/snip]
>
> A very small nail up against a small colored wax cylinder is what came
> to mind, and I laughed a great deal at the animation in my head.
In Pennsyltucky, we call them things "candles".
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.
--- End Message ---
--- Begin Message ---
Jim Lucas wrote:
Dan wrote:
Unfortunatly javascript can't access the filesystem so it can't get
filenames. The closest way you could do something like this would be
to use Java (not javascript, totally different). It's a permissions
thing, just the way JS and everything else is designed.
- Dan
[···]
Library should be compatible with Firefox (Lin, Win, Mac), IE and
Safary.
Thanks in advance for any suggestion(s).
Andrei
In fact you can access the filesystem with "signed" javascript scripts.
Which by "signing" you Javascript, you will be allowed to access the
local file system.
But, again, it is all about the permissions.
Jim
Actually no. Javascript doesn't allow for client's FS access for
security reasons, as noted before.
What you're probably talking about is IE's proprietary implementation
and the use of COM objects (and there goes the security), but Andrei
says the solution should be cross-browser, so this doesn't look like an
option.
Rafael.
--- End Message ---
--- Begin Message ---
At 12:30 AM -0500 11/29/07, Robert Cummings wrote:
On Wed, 2007-11-28 at 22:19 -0700, Jon Westcot wrote:
>
$123,456.78 becomes 123456.78
$24,680 becomes 24680
1234B becomes 1234
$number = ereg_replace( '[^[:digit:].]', '' );
Cheers,
Rob.
Sweet.
Another one of those staple functions we all should have (or at least me).
Thanks,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
I remember once coming across a bit of php code that displayed the
"created" date of a jpeg image. I cannot find it, and I cannot find
anything related to that in tfm. Can someone give me a push in the
general direction? Thanks in advance.
Dotan Cohen
http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
--- End Message ---
--- Begin Message ---
On 01/12/2007, Dotan Cohen <[EMAIL PROTECTED]> wrote:
> I remember once coming across a bit of php code that displayed the
> "created" date of a jpeg image. I cannot find it, and I cannot find
> anything related to that in tfm. Can someone give me a push in the
> general direction? Thanks in advance.
>
I should clarify: the date that I need is not the date of the file
that the filesystem knows about. I need the date that is in the exif
data. Thanks.
Dotan Cohen
http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
--- End Message ---
--- Begin Message ---
On 01/12/2007, Dotan Cohen <[EMAIL PROTECTED]> wrote:
> On 01/12/2007, Dotan Cohen <[EMAIL PROTECTED]> wrote:
> > I remember once coming across a bit of php code that displayed the
> > "created" date of a jpeg image. I cannot find it, and I cannot find
> > anything related to that in tfm. Can someone give me a push in the
> > general direction? Thanks in advance.
> >
>
> I should clarify: the date that I need is not the date of the file
> that the filesystem knows about. I need the date that is in the exif
> data. Thanks.
>
Alright, found it:
http://il2.php.net/manual/en/function.exif-read-data.php
Sorry for the noise.
Dotan Cohen
http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
--- End Message ---
--- Begin Message ---
On Nov 30, 2007 10:00 PM, tedd <[EMAIL PROTECTED]> wrote:
> At 2:00 PM +1100 11/30/07, Chris wrote:
> >>Out of curiosity, what SQL server (and version) are you using? I
> >>currently have MySQL 5.0.33 on my dev box and I had no problem with the
> >>query I gave you. Perhaps it's a version issue. There really shouldn't
> >>be a problem updating a table that also occurs in the select query since
> >>the select query should take place before the insert.
> >
> >He wasn't doing an insert/select, he was doing an update with two
> >tables joined together.
> >
> ><copy>
> >
> >I thought that --
> >
> >UPDATE user1 u1, user2 u2
> >SET u1.login = u2.login, u1.password = u2.password
> >WHERE u1.username = u2.username
> >
> >-- would work, but it don't.
>
>
> Yes, that was true. But considering that it no longer worked, I moved
> on. I still have no clue as to why four months ago the code ran and
> now it doesn't -- other than the host upgraded. But, I don't see how
> that could have affected things.
>
> As for MySQL version, it's now 3.23.58 -- but I don't know what it
> was before the upgrade -- could have been the same. I dunno.
>
> Thanks for the interest.
>
> Cheers,
>
> tedd
>
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
It actually sounds like they may have downgraded. MySQL 4.x and
5.x shouldn't have a problem with the query, but 3.23 probably won't
do it properly. If it's a cPanel host, they may have an old version
of cPanel still running on the server, which would include the 3.23
option. If that is, in fact, the case.... jump ship. This will only
be the first of many problems.
And on a side note, wasn't 3.23 the first REAL stable version of
MySQL accepted at large for production use? I think I recall playing
around with 2.x, but it seems to me that, for the longest time,
everyone was on 3.23. Am I perhaps simply having a premature senior
moment?
Happy December, by the way.
--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.
--- End Message ---
--- Begin Message ---
I want to open a database connection at program initialization and use
that very same connection via globals initilizating ( loading from db)
other objects.
Basically
index.php
$db=new mysqli(host,us,pass,db);
if(mysqli_connect_errno()){
die('errordb conex');
}
switch ($var){
display1:
$obj=new obj_x();
$obj->load();
$obj->display();
break;
display2:
$obj=new obj_y();
$obj->load();
$obj->display();
break;
}
------------------
class obj_x{
function load(){
globals $db;
$sql="select ....);
$ret=$->query($sql); // XX
...
}
}
fails at XX with Warning: mysqli::query() [function.mysqli-query]:
Couldn't fetch mysqli in class file .... line XX
Any hints ??. I am using php 5.1.6 with linux/ubuntu.
Thanks.
JCG
--- End Message ---
--- Begin Message ---
julian wrote:
I want to open a database connection at program initialization and use
that very same connection via globals initilizating ( loading from db)
other objects.
Basically
index.php
$db=new mysqli(host,us,pass,db);
if(mysqli_connect_errno()){
die('errordb conex');
}
switch ($var){
display1:
$obj=new obj_x();
$obj->load();
$obj->display();
break;
display2:
$obj=new obj_y();
$obj->load();
$obj->display();
break;
}
------------------
class obj_x{
function load(){
globals $db;
$sql="select ....);
$ret=$->query($sql); // XX
...
}
}
fails at XX with Warning: mysqli::query() [function.mysqli-query]:
Couldn't fetch mysqli in class file .... line XX
Any hints ??. I am using php 5.1.6 with linux/ubuntu.
Thanks.
JCG
there is typo. obviously I try to access via $db->query($sql);
--- End Message ---
--- Begin Message ---
thanks, but that won't work. i need to see post data from other people
out there, not my own data. still a mystery to me why php doesn't let
developers see incoming raw data.
On 01/12/2007, Dan <[EMAIL PROTECTED]> wrote:
> ""Olav Mørkrid"" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > hello
> >
> >
> > how can i get a raw and untouched printout of a multipart/form-data
> > POST? i need this to analyze what certain user agents do wrong when
> > uploading files.
> >
> > what happens is that php just fails to put files into $_FILES, and
> > gives no way of seeing the original posting and exactly what is wrong
> > with it.
> >
> > according to the manual, neither "always_populate_raw_post_data" nor
> > <php://input> work for multipart/form-data.
>
> Go get Ethereal http://www.ethereal.com/ start the program, set which
> network card you want to use (you probably only have one), start capture.
> You'll now see all the packets going down the wire. Go ahead and do the
> post and you'll be able to see the post data.
>
> - Dan
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
On Dec 1, 2007 2:13 PM, Olav Mørkrid <[EMAIL PROTECTED]> wrote:
> thanks, but that won't work. i need to see post data from other people
> out there, not my own data. still a mystery to me why php doesn't let
> developers see incoming raw data.
>
i think this is what youre looking for:
*$HTTP_RAW_POST_DATA*
see also
http://www.php.net/manual/en/ini.core.php#ini.always-populate-raw-post-data*
*
-nathan
--- End Message ---