|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-01-16 12:56 UTC] danbeck at dealnews dot com
The following code does not work properly
$number = "999.00";
$precision = 2;
echo preg_replace("/\.0{$precision}/", "", $number);
it echos 999.00
But if you escape the first `{' bracket, the regular expression works properly
echo preg_replace("/\.0\{$precision}/", "", $number);
it echos 999
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 23 09:00:02 2025 UTC |
The {$var} construct is interpreted specially in the double-quoted strings by the Zend engine - it will interpolate the variable so you indeed need to escape it with a backslash. This is not a PCRE problem.