Hello everyone,
I encountered a problem for using the preg_replace method in a text which content a price formatted as $123.45.
<?php
$xRegex = '#{params:.+?}#s';
$sPrice = "$123.45";
$sContent = "Price is {params:xxx}.";
echo preg_replace( $xRegex, $sPrice, $sContent, 1 );
?>
When i'm doing this, I got : Price is 3.45
After some research on the PHP documentation, and if I undesrtood correctly, preg_replace consider $ as a reference.
The only I way I could get over this problem is by using urlencode() and urldecode() as following:
<?php
$xRegex = '#{params:.+?}#s';
$sPrice = "$123.45";
$sContent = "Price is {params:xxx}.";
echo urldecode(preg_replace( $xRegex, urlencode($sPrice), $sContent, 1 ));
?>
Is there an other way for doing this? Am I thinking this correctly?
Thanks for any ideas or advices!