RE: [PHP] what's wrong with ereg_replace's \\1 ?
| From: | Kris Erickson | Date: | Mon, 28 Aug 2000 02:04:33 +0000 |
| Subject: | RE: [PHP] what's wrong with ereg_replace's \\1 ? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-13880@lists.php.net to get a copy of this message | ||
There is no way for the function call to transcript to recieve the \\1 value from ereg_replace, it
is only going to get the literal \\1 and then the output from transcript will be sent to
ereg_replace. The only way that you could do it is with preg_replace (which is part of the much
faster and more flexible preg_functions, but has the disadvantage that it inherits all the
quirkiness of perl regular expressions). To do what you want to do is quite easy (WARNING: Untested
code, but you should get the idea).
preg_replace("/&([^;]+);/e", "transcript('\\1', $iso8859_1)",
$string);
Note that you have to use /e modifier, which tells the preg_replace interpreter to execute the what
it finds in the replacement string. See http://www.php.net/manual/function.preg-replace.php
for full details.
-----Original Message-----
From: Jakob
To: php-general@lists.php.net
Sent: 27/08/00 8:52 AM
Subject: [PHP] what's wrong with ereg_replace's \\1 ?
Hi,
I have the following $string = "abcd °efgh äijklm".
I need to replace the character entities with their numeric counterparts
(XML requirement).
I have a function transcript($entity, $map) that takes an $entity and
returns the numeric equivalent if it exists.
I thought I could do this:
ereg_replace("&([^;]+);", transcript("\\1", $iso8859_1),
$string);
But apparently in this function call the "\\1" is taken literally ...
Does anybody know I could achieve the same effect using another way?
Thank you very much in advance,
Jakob.