|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8741 preg functions interpret { as part of variable interpolation
Submitted: 2001-01-16 12:56 UTC Modified: 2001-07-21 04:32 UTC
From: danbeck at dealnews dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 4.0.3pl1 OS: Linux 2.x, Redhat 6.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: danbeck at dealnews dot com
New email:
PHP Version: OS:


 [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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-01-16 15:40 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.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 04 13:01:27 2023 UTC