Consider the following example....
The issue is with the preg_replace which is used to replace the variables total_balance_overriden and total_balance.
$text = 'this: {{total_balance_overridden}} - that: {{total_balance}}';
$total = '$517.50';
$overiddentotal = '$390.00';
$text = preg_replace('/{{total_balance_overridden}}/', $overiddentotal, $text);
$text = preg_replace('/{{total_balance}}/', $total, $text);
echo $total;
echo $overiddentotal;
echo $text;
This gives me...
$517.50
$390.00
this: 0.00 - that: 7.50
It appears that the $total and $overiddentotal vars have the correct output, but when they have been replaced using the preg_replace, their length has been stripped, and the currency sign and first two numbers are missing. Any ideas why?
Note: If i replace the dollar sign with a pound sign it works! I get...
this: £390.00 - that: £517.50
So is the dollar sign and 2 numbers some sort of special character or var thats getting stripped?
Dollar signs are special characters in replacement strings, they normally refer to captured substrings from the match. If you want a literal dollar sign, you have to escape it:
$total = '\$517.50';
$overiddentotal = '\$390.00';
Note also, in this case, there's no need for regex at all. Just use str_replace()
and you won't have this issue.