php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-01-16 15:40 UTC] andrei@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 15:01:28 2024 UTC