After battling with this for a while I now can't reproduce the problem.
Apologies for an un-necessary post.
----- Original Message -----
From: "Angus Mann" <angusm...@pobox.com>
To: "PHP-General" <email@example.com>
Sent: Wednesday, January 27, 2010 9:02 AM
Subject: [PHP] Strange behaviour with str_ireplace()
Hi all. I found some unexpected behaviour with str_ireplace.
To summarize, if the $replace term is a number, but formatted as currency
with trailing zero's (34.50) the function drops the trailing zero.
$message="You owe me #amount#.";
$message1 = str_ireplace("#amount#,sprintf("%01.2f",$price),$message);
$message2 = str_ireplace("#amount#,"$".sprintf("%01.2f",$price),$message);
$message1 will yield "You owe me 34.4"
$message2 will yield "You owe me $34.40"
So in other words, if the replace term can be interpreted as a number, it
will be, including truncation of zero's.
I didn't expect this, because as the function name suggests, it's a *string*
Fortunately I can just add a $ to the amount and make it work as a string,
not a number but this would not always be the case.
Is this by design, or is it a bug?
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php