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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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: Tue Oct 08 21:01:27 2024 UTC