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.

Example :

$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?

Reply via email to