Bug #11540 Updated: Backslash and regular expressions
| From: | andre@php.net | Date: | Wed, 20 Jun 2001 10:39:15 +0000 |
| Subject: | Bug #11540 Updated: Backslash and regular expressions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-57363@lists.php.net to get a copy of this message | ||
ID: 11540
Updated by: andre
Reported By: oroos@fmlogistic.pl
Old-Status: Closed
Status: Bogus
Bug Type: *Regular Expressions
Operating system:
PHP Version: 4.0.5
Assigned To:
Comments:
Previous Comments:
---------------------------------------------------------------------------
[2001-06-20 03:02:45] oroos@fmlogistic.pl
I am told that I should put four backslahes in my pattern to make it match a single backslash.
This is good in static patterns. But my pattern is a variable string which I want to put in good
pattern format using the fonction preg_quote.
But this function transforms one backslash in only two backshlashes (and not 4 !)... Thus, the only
way to make my program work is to apply two times this function preg_quote. This works, but this is
not very nice, is it ?
So, isn't there a bug in function preg_quote ?
Thanks in advance,
Olivier Roos
---------------------------------------------------------------------------
[2001-06-18 11:53:03] oroos@fmlogistic.pl
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:
XX
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
---------------------------------------------------------------------------
ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=11540&edit=2