php-general Digest 24 Feb 2006 14:53:10 -0000 Issue 3982

Topics (messages 231001 through 231021):

Floored!
        231001 by: Ben Miller
        231003 by: Ruben Rubio Rey
        231004 by: Rasmus Lerdorf
        231005 by: Brandon Enright

PHP Manual in PDF format
        231002 by: Kaushal Shriyan

list days between two dates
        231006 by: pol
        231021 by: tedd

Re: Calling API on Windows?
        231007 by: Jochem Maas
        231008 by: HoWang Wang

loop Q
        231009 by: William Stokes
        231010 by: Duncan Hill
        231011 by: ÃmìtVërmå
        231012 by: Jochem Maas
        231014 by: William Stokes
        231019 by: Jochem Maas

Re: base64_encode, forward slashes and mod_rewrite
        231013 by: Jared Williams

[SOLVED] Problem with mail() on Debian
        231015 by: George Pitcher

Date question
        231016 by: William Stokes
        231017 by: William Stokes
        231018 by: ÃmìtVërmå

Compiling PHP with freetype2 on MacOS X
        231020 by: Marcus Bointon

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:
        php-general@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
If anyone has an answer for this, I would be greatly appreciative.

I was trying to compare two values, the first is the total cost of products
to be refunded, and the second is the original order total.  To the naked
eye, they both were coming out as 102.85, yet an if($Refund_Amount >
$Order_Total) was coming back true, so.....

I ran some tests, and did the following:

                $Order_Total = sprintf("%01.20f",$Order_Total);
                $Refund_Amount = sprintf("%01.20f",$Refund_Amount);

which produced:

                $Order_Total = 102.84999999999999431566
and             $Refund_Amount = 102.85000000000000852651

so, I figured I would try the following to make sure that the figures in the
database weren't weird:

                $Bar = 102.85;
                $Foo = sprintf("%01.20f",$Bar);

                echo "\$Foo = $Foo";

which produced:

                $Foo = 102.84999999999999431566;

I am completely lost.

--- End Message ---
--- Begin Message ---
|What PHP versioan are u using? (Maybe a known bug?)
What options did u use to compile?

|Temporarily solutions ...|
- round($Bar, 2) Or
- intval($Bar*100)/100
|
Ben Miller wrote:

If anyone has an answer for this, I would be greatly appreciative.

I was trying to compare two values, the first is the total cost of products
to be refunded, and the second is the original order total.  To the naked
eye, they both were coming out as 102.85, yet an if($Refund_Amount >
$Order_Total) was coming back true, so.....

I ran some tests, and did the following:

                $Order_Total = sprintf("%01.20f",$Order_Total);
                $Refund_Amount = sprintf("%01.20f",$Refund_Amount);

which produced:

                $Order_Total = 102.84999999999999431566
and             $Refund_Amount = 102.85000000000000852651

so, I figured I would try the following to make sure that the figures in the
database weren't weird:

                $Bar = 102.85;
                $Foo = sprintf("%01.20f",$Bar);

                echo "\$Foo = $Foo";

which produced:

                $Foo = 102.84999999999999431566;

I am completely lost.


--- End Message ---
--- Begin Message ---
Ben Miller wrote:
If anyone has an answer for this, I would be greatly appreciative.

I was trying to compare two values, the first is the total cost of products
to be refunded, and the second is the original order total.  To the naked
eye, they both were coming out as 102.85, yet an if($Refund_Amount >
$Order_Total) was coming back true, so.....

I ran some tests, and did the following:

                $Order_Total = sprintf("%01.20f",$Order_Total);
                $Refund_Amount = sprintf("%01.20f",$Refund_Amount);

which produced:

                $Order_Total = 102.84999999999999431566
and             $Refund_Amount = 102.85000000000000852651

so, I figured I would try the following to make sure that the figures in the
database weren't weird:

                $Bar = 102.85;
                $Foo = sprintf("%01.20f",$Bar);

                echo "\$Foo = $Foo";

which produced:

                $Foo = 102.84999999999999431566;

I am completely lost.

Read the note on floating point precision here:

  http://us3.php.net/manual/en/language.types.float.php

You need to either work completely in pennies and only convert to dollars for display purposes so you are always working with integers, or you need to introduce a little fuzz factor whenever you are doing operations on floating point values.

There is simply no way for a computer to accurately represent a fraction with anything other than an estimation. The typical fix if you don't want to switch to using integer math is to add an appropriate fuzz factor. Like this:

  $fuzz = 0.0000001;
  if(floor($value+$fuzz) == 10) ...

That is, if the floating point $value happens to be 9.99999999999 or 10.00000000001 then applying this fuzz factor and doing the floor operation, you will always get 10 as long as your fuzz factor is larger than the precision error of your machine.

-Rasmus

--- End Message ---
--- Begin Message ---
On Thu, 2006-02-23 at 23:38 -0700, Ben Miller wrote:
> If anyone has an answer for this, I would be greatly appreciative.
> 
> I was trying to compare two values, the first is the total cost of products
> to be refunded, and the second is the original order total.  To the naked
> eye, they both were coming out as 102.85, yet an if($Refund_Amount >
> $Order_Total) was coming back true, so.....
> 
> I ran some tests, and did the following:
> 
>               $Order_Total = sprintf("%01.20f",$Order_Total);
>               $Refund_Amount = sprintf("%01.20f",$Refund_Amount);
> 
> which produced:
> 
>               $Order_Total = 102.84999999999999431566
> and           $Refund_Amount = 102.85000000000000852651
> 
> so, I figured I would try the following to make sure that the figures in the
> database weren't weird:
> 
>               $Bar = 102.85;
>               $Foo = sprintf("%01.20f",$Bar);
> 
>               echo "\$Foo = $Foo";
> 
> which produced:
> 
>               $Foo = 102.84999999999999431566;
> 
> I am completely lost.
> 

This is an oversimplification but basically to represent any decimal in
binary you need to do so as the sum of the reciprocal powers of two.
That is, .5 + .25 + .125 + .0625... an so on.  If you have nice even
numbers like .75 then a few bits will do.  If you don't you need
increasingly smaller terms until you reach the sum.  You need 37 bits
just to represent .85 exactly.  The floating point numbers your are
using only have 32 bits total (and not even all of them are mantissa
bits).


A description of the standard:

http://www.psc.edu/general/software/packages/ieee/ieee.html


An excellent treatise of the subject:

http://docs.sun.com/source/806-3568/ncg_goldberg.html


Brandon

-- 
Brandon Enright
UCSD ACS/Network Operations
[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
Hi ALL

I am looking out for PHP Manual in PDF Format

Thanks in Advance

Regards

Kaushal

--- End Message ---
--- Begin Message ---
Anyony know a funtction to do this?
I need to popup a select with the dates.

thank's
Pol 

--- End Message ---
--- Begin Message ---
Anyony know a funtction to do this?
I need to popup a select with the dates.

thank's
Pol

Pol:

Try this:

http://www.weberdev.com/get_example-4330.html

tedd
--
--------------------------------------------------------------------------------
http://sperling.com

--- End Message ---
--- Begin Message ---
HoWang Wang wrote:
> Hi,
> 
> How can I use it?
> For example:
> [lib='user32.dll'] int MessageBoxA(int handle, char *text, char
> *caption, int type);
> How can I write this sentence?
> What is the format?
> And I want to use GetComputerNameA, what can I do?
> 
> <?php
> $win32_idl = "[lib='user32.dll'] int MessageBoxA(int handle, char *text,
> char *caption, int type);
> [lib='kernel32.dll'] int GetComputerNameA (char *lpBuffer, DWORD nSize);";
> 
> $ffi = new ffi($win32_idl);
> $compname = '';
> $r = $ffi->GetComputerNameA($compname,255);
> echo $r; //Debug
> echo $ffi->MessageBoxA(0, "The Computer Name is " . $compname, "Test", 0);
> ?>
> 
> doesn't work, it give me an error.

could you please move the roof of your house so I
can see your computer monitor? (what's the error?)

did you search for the error on google or yahoo or
<insert-favorite-search-engine>?


> Please help, thx!
> 
> 
> Jochem Maas wrote:
> 
>>Hi Ho, (7 dwarfs anyone? ;-)
>>
>>click this link to download php4.4.2 (not the installer version)
>>it contains the DLL your looking for:
>>
>>http://hk.php.net/get/php-4.4.2-Win32.zip/from/a/mirror
>>
>>in the event that your using php5 then w32api is no longer
>>available - it has been replaced with fcc:
>>
>>http://pecl.php.net/package/ffi
>>
>>you can download a binary ddl (built automatically from cvs) here:
>>http://pecl4win.php.net/ext.php/php_ffi.dll
>>
>>
>>HoWang Wang wrote:
>>
>>
>>>Dear all,
>>>
>>>I have a question on w32api ( http://hk.php.net/manual/en/ref.w32api.php
>>>). I'm developing a command line program with PHP on windows, and I want
>>>to call some API. But I cannot found the dll required for the w32api
>>>extension. I'm using PHP/5.0.5, does anyone have an idea? Or there is
>>>another extension can call Windows API?
>>>
>>>Thanks
>>>Ho Wang
>>>
> 
> 

--- End Message ---
--- Begin Message ---
Okay, here is the error:
http://hwhome.hkto.net:808/apidie.jpg
I'm using CHT version of windows, but I think you should seen this
window before.

I've searched on google, but I find lots of ffi that != Foreign Function
Interface :(

I found this:
http://www.cweiske.de/download/phpgtk/pear/System_WinDrives.phps which
use PHP's w32api on PHP4 and use FFI on PHP5. But it provide a simple
example of using ffi only, and I'm still confused on it.

Please help, Thx!

Ho Wang


Jochem Maas wrote:
> HoWang Wang wrote:
> 
>>Hi,
>>
>>How can I use it?
>>For example:
>>[lib='user32.dll'] int MessageBoxA(int handle, char *text, char
>>*caption, int type);
>>How can I write this sentence?
>>What is the format?
>>And I want to use GetComputerNameA, what can I do?
>>
>><?php
>>$win32_idl = "[lib='user32.dll'] int MessageBoxA(int handle, char *text,
>>char *caption, int type);
>>[lib='kernel32.dll'] int GetComputerNameA (char *lpBuffer, DWORD nSize);";
>>
>>$ffi = new ffi($win32_idl);
>>$compname = '';
>>$r = $ffi->GetComputerNameA($compname,255);
>>echo $r; //Debug
>>echo $ffi->MessageBoxA(0, "The Computer Name is " . $compname, "Test", 0);
>>?>
>>
>>doesn't work, it give me an error.
> 
> 
> could you please move the roof of your house so I
> can see your computer monitor? (what's the error?)
> 
> did you search for the error on google or yahoo or
> <insert-favorite-search-engine>?
> 
> 
> 
>>Please help, thx!
>>
>>
>>Jochem Maas wrote:
>>
>>
>>>Hi Ho, (7 dwarfs anyone? ;-)
>>>
>>>click this link to download php4.4.2 (not the installer version)
>>>it contains the DLL your looking for:
>>>
>>>http://hk.php.net/get/php-4.4.2-Win32.zip/from/a/mirror
>>>
>>>in the event that your using php5 then w32api is no longer
>>>available - it has been replaced with fcc:
>>>
>>>http://pecl.php.net/package/ffi
>>>
>>>you can download a binary ddl (built automatically from cvs) here:
>>>http://pecl4win.php.net/ext.php/php_ffi.dll
>>>
>>>
>>>HoWang Wang wrote:
>>>
>>>
>>>
>>>>Dear all,
>>>>
>>>>I have a question on w32api ( http://hk.php.net/manual/en/ref.w32api.php
>>>>). I'm developing a command line program with PHP on windows, and I want
>>>>to call some API. But I cannot found the dll required for the w32api
>>>>extension. I'm using PHP/5.0.5, does anyone have an idea? Or there is
>>>>another extension can call Windows API?
>>>>
>>>>Thanks
>>>>Ho Wang
>>>>
>>
>>

--- End Message ---
--- Begin Message ---
What does this do in a for loop?

$counter+=1



Thanks

-Will

--- End Message ---
--- Begin Message ---
On Friday 24 February 2006 10:34, William Stokes wrote:
> What does this do in a for loop?
>
> $counter+=1

Increments $counter.

--- End Message ---
--- Begin Message ---
It depicts
$counter = $counter+1;

William Stokes wrote:

What does this do in a for loop?

$counter+=1



Thanks

-Will


--- End Message ---
--- Begin Message ---
William Stokes wrote:
What does this do in a for loop?

$counter+=1


it's shorthand for $counter = $counter + 1;
which in this case (because 1 is being added)
can also be written as:

$counter++;

or

++$counter;


those last 2 alternatives give the same result
but they are _not_ exactly equivalent - it has to do
with when the incrementation is done when such expression
appears inside a more complex expression e.g.

$counter = 1;
$x = ++$counter;
$counter = 1;
$y = $counter++;
echo $x,",",$y,"\n"; // outputs: 2,1




Thanks

-Will


--- End Message ---
--- Begin Message ---
Cheers!

"Jochem Maas" <[EMAIL PROTECTED]> kirjoitti 
viestissä:[EMAIL PROTECTED]
> William Stokes wrote:
>> What does this do in a for loop?
>>
>> $counter+=1
>>
>
> it's shorthand for $counter = $counter + 1;
> which in this case (because 1 is being added)
> can also be written as:
>
> $counter++;
>
> or
>
> ++$counter;
>
>
> those last 2 alternatives give the same result
> but they are _not_ exactly equivalent - it has to do
> with when the incrementation is done when such expression
> appears inside a more complex expression e.g.
>
> $counter = 1;
> $x = ++$counter;
> $counter = 1;
> $y = $counter++;
> echo $x,",",$y,"\n"; // outputs: 2,1
>
>
>>
>>
>> Thanks
>>
>> -Will
>> 

--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] wrote:
William Stokes wrote:

What does this do in a for loop?

$counter+=1


I read it as if he'd come across this:

for ($counter=0; $counter<$stopper; $counter+=1)
{
  ... lots of code ...

  $counter+=1;
}

Which, I think, would increment the counter twice on each pass
through. The line in the loop needs deleting.

That's just how I read it.

be ware of making assumptions like that, for instance
the loop could very well be:

for ($counter=0; $counter<$stopper;)
{
        // ... lots of code ...
        $counter+=1;
}

or


for ($counter=0; $counter<$stopper;$counter+=1)
{
        // ... lots of code ... 
}

which are both valid.


Actually, I'm testing this list .. every time I post it never appears
so I'm wondering whether this will / the problem's been fixed.

it got thru :-)


J

--- End Message ---
--- Begin Message ---
 
There are variants of base64,  which replace the + / characters with something 
less likely to cause problems.

http://en.wikipedia.org/wiki/Base64

Jared

> 
> sorry Ive done it again, for anyones interest, you might have 
> to urlencode the string twice for mod_rewrite to accept 
> encrypted and base64_encoded strings which add slashes and 
> ampersands into their strings.
> 
> It is confirmed there is a bug in mod_rewrite and doesnt like 
> the urlencoded %2F characters.
> 
> On 24/02/2006, at 10:31 AM, Dan Rossi wrote:
> 
> > Continueing on my prior problem, Ive discovered that base64_encode 
> > adds forward slashes in its encoded string, when its urlencoded it 
> > becomes something like
> >
> > /feeds/UmFuZG9tSVZd%2FMChU7sMQqdUi%2FrgYHD7
> >
> >
> > mod_rewrite doesnt seem to like the %2F in the string and 
> fails with a
> > 404 as it doesnt get a match using
> >
> > RewriteRule ^feeds/(.*)$ /refer.php?$1 [L,NE]
> >
> > What should i do ? Should i replace the / with a different 
> character 
> > then convert it back later ?
> 
> --
> PHP General Mailing List (http://www.php.net/) To 
> unsubscribe, visit: http://www.php.net/unsub.php
> 

--- End Message ---
--- Begin Message ---
Hi,

Thanks to David - his suggestion to comment out the php.ini sendmail_path
line and reverting to using Manuel's email class solved the problem.

Many thanks to all.

George

> -----Original Message-----
> From: Manuel Lemos [mailto:[EMAIL PROTECTED]
> Sent: 23 February 2006 7:58 pm
> To: php-general@lists.php.net
> Subject: Re: [PHP] Problem with mail() on Debian
>
>
> Hello,
>
> on 02/23/2006 11:32 AM George Pitcher said the following:
> >  My apache error.log says:
> >
> > sh: line 1: /usr/sbin/sendmail -t: no such file or directory
>
> /usr/sbin/sendmail is not the correct sendmail program path. The correct
> path is /usr/lib/sendmail . It may be odd that a program is located in
> /usr/lib but that has always been the standard path for sendmail and
> compatible MTA. Sometimes it is a symbolic link to /usr/sbin/sendmail
> but that is not necessarily true.
>
> --
>
> Regards,
> Manuel Lemos
>
> Metastorage - Data object relational mapping layer generator
> http://www.metastorage.net/
>
> PHP Classes - Free ready to use OOP components written in PHP
> http://www.phpclasses.org/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Hello,

I have a datetime column in MySQL DB. How can I match to that column from 
php code if I only have the date information available.

2006-02-24 12:00:00  against    2006-02-24

This might be more SQL question sorry about that.

Thanks
-Will

--- End Message ---
--- Begin Message ---
Yep. Nevermind...

(and back to sleep)

""William Stokes"" <[EMAIL PROTECTED]> kirjoitti 
viestissä:[EMAIL PROTECTED]
> Hello,
>
> I have a datetime column in MySQL DB. How can I match to that column from 
> php code if I only have the date information available.
>
> 2006-02-24 12:00:00  against    2006-02-24
>
> This might be more SQL question sorry about that.
>
> Thanks
> -Will 

--- End Message ---
--- Begin Message --- If you are only avail with date-information then too you can use existing DATETIME field as following query..

INSERT INTO `test` (`testingdate` ) VALUES ( '2006-06-06');

it will take care of itself.

Second way is you can change DATETIME field to VARCHAR (if you're not going to use those dates in date related calculations and MySQL functions etc.)

Both ways it would work fine.




William Stokes wrote:

Hello,

I have a datetime column in MySQL DB. How can I match to that column from php code if I only have the date information available.

2006-02-24 12:00:00  against    2006-02-24

This might be more SQL question sorry about that.

Thanks
-Will


--- End Message ---
--- Begin Message --- Recently I've not been able to compile PHP 5.1.2 on OS X 10.4 with gd and freetype2 support. I've found various threads on this, but none of the proposed fixes work. My configure line includes:

--with-gd=/sw --with-freetype-dir=/sw/lib/freetype2 --with-t1lib=/sw

It doesn't report any problems when configuring:

...
checking for GD support... yes
checking for the location of libjpeg... /sw
checking for the location of libpng... /sw
checking for the location of libXpm... no
checking for FreeType 1.x support... /sw
checking for FreeType 2... /sw/lib/freetype2
checking for T1lib support... /sw
checking whether to enable truetype string function in GD... yes
checking whether to enable JIS-mapped Japanese font support in GD... no
checking for jpeg_read_header in -ljpeg... (cached) yes
checking for png_write_image in -lpng... (cached) yes
If configure fails try --with-xpm-dir=<DIR>
checking for FreeType 1 support... no - FreeType 2.x is to be used instead
checking for T1_StrError in -lt1... (cached) yes
checking for gdImageString16 in -lgd... (cached) yes
checking for gdImagePaletteCopy in -lgd... (cached) yes
checking for gdImageCreateFromPng in -lgd... (cached) yes
checking for gdImageCreateFromGif in -lgd... (cached) yes
checking for gdImageGif in -lgd... (cached) yes
checking for gdImageWBMP in -lgd... (cached) yes
checking for gdImageCreateFromJpeg in -lgd... (cached) yes
checking for gdImageCreateFromXpm in -lgd... (cached) yes
checking for gdImageCreateFromGd2 in -lgd... (cached) yes
checking for gdImageCreateTrueColor in -lgd... (cached) yes
checking for gdImageSetTile in -lgd... (cached) yes
checking for gdImageEllipse in -lgd... no
checking for gdImageSetBrush in -lgd... (cached) yes
checking for gdImageStringTTF in -lgd... (cached) yes
checking for gdImageStringFT in -lgd... (cached) yes
checking for gdImageStringFTEx in -lgd... (cached) yes
checking for gdImageColorClosestHWB in -lgd... (cached) yes
checking for gdImageColorResolve in -lgd... (cached) yes
checking for gdImageGifCtx in -lgd... (cached) yes
checking for gdCacheCreate in -lgd... (cached) yes
checking for gdFontCacheShutdown in -lgd... (cached) yes
checking for gdFreeFontCache in -lgd... (cached) yes
checking for gdNewDynamicCtxEx in -lgd... (cached) yes
checking for gdImageCreate in -lgd... (cached) yes

but when I make:

/Users/marcus/src/php-5.1.2/ext/gd/gd.c: In function 'zm_info_gd':
/Users/marcus/src/php-5.1.2/ext/gd/gd.c:505: error: 'FREETYPE_MAJOR' undeclared (first use in this function) /Users/marcus/src/php-5.1.2/ext/gd/gd.c:505: error: (Each undeclared identifier is reported only once /Users/marcus/src/php-5.1.2/ext/gd/gd.c:505: error: for each function it appears in.) /Users/marcus/src/php-5.1.2/ext/gd/gd.c:505: error: 'FREETYPE_MINOR' undeclared (first use in this function)
/Users/marcus/src/php-5.1.2/ext/gd/gd.c: In function 'php_imagechar':
/Users/marcus/src/php-5.1.2/ext/gd/gd.c:2817: warning: pointer targets in passing argument 1 of 'strlen' differ in signedness /Users/marcus/src/php-5.1.2/ext/gd/gd.c: In function 'php_imagettftext_common': /Users/marcus/src/php-5.1.2/ext/gd/gd.c:3197: warning: pointer targets in passing argument 4 of 'gdImageStringFTEx' differ in signedness /Users/marcus/src/php-5.1.2/ext/gd/gd.c:3197: warning: pointer targets in passing argument 9 of 'gdImageStringFTEx' differ in signedness /Users/marcus/src/php-5.1.2/ext/gd/gd.c:3203: warning: pointer targets in passing argument 4 of 'gdImageStringFT' differ in signedness /Users/marcus/src/php-5.1.2/ext/gd/gd.c:3203: warning: pointer targets in passing argument 9 of 'gdImageStringFT' differ in signedness
make: *** [ext/gd/gd.lo] Error 1

Those undefined constants sound like it's missing a header file somewhere.

I've also tried using the built-in freetype2 lib using --with- freetype-dir=/usr/X11R6 but that gives me the same error. I've also tried using the bundled gd lib, again I get the same error. I've cut my configure line down to just the options for the environment, gd and freetype. I've looked in /sw/lib/freetype2/include/freetype2/ freetype/freetype.h and the missing constants are correctly defined in there, and also in /usr/X11R6/include/freetype2/freetype/ freetype.h Those files should be found using the paths I gave in configure.

Anyone got any idea how I can fix this?

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

--- End Message ---

Reply via email to