Am Mittwoch, 01.10.03 um 22:27 Uhr schrieb Chris W. Parker:
Seeing as how you haven't had a response yet, I'll ask this: what
exactly is your question? I'm not sure as to what it is that you want.

My question are:
a) Why does the PHP manual say that backslashes get escaped by writing them twice while this causes an error in my example (see below)?
b) Why does a different input (2.1. and 2.2.) result in the same output (in the example I enclosed)?
c) Why do I hate regular expressions so much?


Choose one.

- Jns

8<
1. The PHP manual sais to escape the escape char, it has to be written twice*, but:
$term = preg_replace('/(\\)/', 'backslash $1', $term);
causes an error** while using three backslashes (see 2.) works.


2.1.
$term = "beg \ end";
print preg_replace('/(\\\)/', 'backslash $1', $term);
returns: beg backslash \ end

2.2.
$term = "beg \\ end";
print preg_replace('/(\\\)/', 'backslash $1', $term);
returns: beg backslash \ end (the same as 2.1.)

2.3.
$term = "beg \\\ end";
print preg_replace('/(\\\)/', 'backslash $1', $term);
returns: beg backslash \backslash \ end

* http://www.php.net/manual/en/pcre.pattern.syntax.php
** "Warning: Compilation failed: missing ) at offset 3 in /home/jonas/public_html/test01.php on line 3"

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to