php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17616 backslash characters handled oddly in preg_replace
Submitted: 2002-06-05 18:17 UTC Modified: 2002-09-25 09:38 UTC
From: john43 at temple dot edu Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 4.3.0-dev OS: linux 2.4.14, pcre
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: john43 at temple dot edu
New email:
PHP Version: OS:

 

 [2002-06-05 18:17 UTC] john43 at temple dot edu
Below are two calls to preg_replace() with different replacement strings. For some reason, they both return the same string.

$s = "A backslash: \\ ";
$s1 = preg_replace("/\\\\/", "\\\\\\",   $s);
$s2 = preg_replace("/\\\\/", "\\\\\\\\", $s);

echo "s : $s  \n";
echo "s1: $s1 \n";
echo "s2: $s2 \n";

------------------
Output:
s : A backslash: \   
s1: A backslash: \\  
s2: A backslash: \\  

------------------


My configuration:

'./configure' '--with-gnu-ld' '--with-apxs=/usr/local/apache/bin/apxs' '--with-mysql=/usr/local/mysql' 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-11 19:44 UTC] iliaa@php.net
updated version.
 [2002-09-25 09:33 UTC] andrei@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


 [2002-09-25 09:35 UTC] andrei@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

In the first case the extension receives replacement string \\\ which is basically \\, since last backslash doesn't quote anything. And in the second case it's \\\\ which is interpolated into \\.
 [2002-09-25 09:38 UTC] iliaa@php.net
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem does not imply a bug in PHP itself.
For a list of more appropriate places to ask for help using PHP,
please visit http://www.php.net/support.php

Thank you for your interest in PHP.

not a bug -> bogus
 [2002-09-25 19:21 UTC] meg at lalooks dot net
what do you people mean, "this isn't a bug"??!

php is such a joke.
 [2002-09-27 13:48 UTC] B_ulrich at t-online dot de
IMHO its a strange Bug!
In PHP 4.0.4.pl1 this Bug doesn't occure.

I used this function to generate LATEX-Files for PDFLATEX.
(In TEX you can force a newline by \\) 
So i used: 
preg_replace("/(\015\012)|(\015)|(\012)/","\\\\\n",$txt);
to insert optional Text to the TEX-File and it work as expected in PHP 4.0.4.pl1
After changeing to PHP 4.2.3 suddenly this didn't work. 
I had to change to:
preg_replace("/(\015\012)|(\015)|(\012)/","\\\\\\\n ",$txt);
This IS a Bug and should become fixed!!!
To check if the Bug is inside PHP or PCRE library i compiled 
PHP 4.0.4.pl1 and PHP 4.2.3 with the same PCRE library and got the same differences between the Versions. There were many changes in the php_pcre.c between the Versions an i think one (or some) of this changes cause this error.

not bogus -> a bug
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Dec 01 10:03:34 2021 UTC