Home > Archive > PHP Language > May 2004 > can't get preg_replace to work at all
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
can't get preg_replace to work at all
|
|
|
| Shouldn't this change the contents of $mHr from "Hi" to "Lo"?
It won't work.
I wonder why.
$mHr="Hi";
preg_replace("/Hi/", "/Lo/", $mHr);
| |
| Alvaro G Vicario 2004-05-12, 7:21 pm |
| *** r wrote/escribió (Wed, 12 May 2004 11:17:35 -0500):
> preg_replace("/Hi/", "/Lo/", $mHr);
Try:
preg_replace("/Hi/g", "Lo", $mHr);
--
--
-- Álvaro G. Vicario - Burgos, Spain
--
| |
|
|
|
|
| Andy Hassall 2004-05-12, 7:21 pm |
| On Wed, 12 May 2004 18:54:13 +0200, Alvaro G Vicario
<alvaro_QUITAR_REMOVE@telecomputeronline.com> wrote:
>*** r wrote/escribió (Wed, 12 May 2004 11:17:35 -0500):
>
>Try:
> preg_replace("/Hi/g", "Lo", $mHr);
The g modifier isn't necessary; unlike the Perl s// operator on which
preg_replace is based, the default is to replace all matches, not just the
first one.
In fact, g isn't even listed in the PCRE manual.
--
Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
|
|
|
|
|