php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20206 escape the escape char in preg_replace
Submitted: 2002-10-31 21:38 UTC Modified: 2002-11-01 03:36 UTC
From: tea at softhome dot net Assigned:
Status: Not a bug Package: *Regular Expressions
PHP Version: 4.2.2 OS: win2k sp3
Private report: No CVE-ID: None
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:
41 + 7 = ?
Subscribe to this entry?

 
 [2002-10-31 21:38 UTC] tea at softhome dot net
let say:
$_SESSION["l"] = 'c/c++';
$_SESSION["l"] = preg_replace("/\\*\/","\/",$_SESSION["l"]);
$_SESSION["l"] = preg_replace("/\\*\+","\+",$_SESSION["l"]);

what i expect is no matter how the user reload the page
$_SESSION["l"] should be 'c\/c\+\+'
i used the reg exp in perl and tried it out, seems logically correct, but it cause an error in my php page.

thx for your attention

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-01 01:43 UTC] tea at softhome dot net
sorry, a typo in the second line of code
$_SESSION["l"] = preg_replace("/\\*\//","\/",$_SESSION["l"]);

i missed a '/'.
 [2002-11-01 01:46 UTC] tea at softhome dot net
line 3 also....
missed a '/' :(

$_SESSION["l"] = 'c/c++';
$_SESSION["l"] = preg_replace("/\\*\//","\/",$_SESSION["l"]);
$_SESSION["l"] = preg_replace("/\\*\+/","\+",$_SESSION["l"]);
 [2002-11-01 03:36 UTC] moriyoshi@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Check your regex pattern again. Two leading backslashes will escape "*".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun May 11 13:01:28 2025 UTC