|  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
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.
Block user comment
Status: Assign to:
Bug Type:
From: tea at softhome dot net
New email:
PHP Version: OS:


 [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


Add a Patch

Pull Requests

Add a Pull Request


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]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Check your regex pattern again. Two leading backslashes will escape "*".
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 23 20:01:31 2024 UTC