Bug #11540: Backslash and regular expressions

From: Date: Mon, 18 Jun 2001 15:53:04 +0000
Subject: Bug #11540: Backslash and regular expressions
Groups: php.dev 
Request: Send a blank email to php-dev+get-56719@lists.php.net to get a copy of this message
From: oroos@fmlogistic.pl Operating system: Windows PHP version: 4.0.5 PHP Bug Type: *Regular Expressions Bug description: Backslash and regular expressions Hello, I have to write a program which replaces backslashes by slashes into HTML code. I would like to do this using regular expressions. Unfortunately, there may be a problem in pattern matching as PHP does not seem to work properly as soon as I add some backslashes in my patterns... Here is a small example which illustrates the problem: <? $test = "X\\X"; // $test is a string containing a backslash echo $test."\n"; echo preg_quote($test)."\n"; echo preg_match("/X\\X/", $test)."\n"; ?> The output of this program is the following: X\X X\\X 0 The '0' means that the preg_match failed... But the pattern of this preg_match was the string $test quoted by preg_quote to become a valid pattern... (as you can see on second line of the output). So this preg_match should output '1', shouldn't it ?? Thanks in advance for any help or advice, Olivier Roos -- Edit Bug report at: http://bugs.php.net/?id=11540&edit=1

« previous php.dev (#56719) next »