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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
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

Pull Requests

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: Sun Dec 22 06:01:30 2024 UTC