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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
38 + 28 = ?
Subscribe to this entry?

 
 [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: Tue Apr 16 05:01:29 2024 UTC