Home > Archive > PHP Language > May 2004 > eregi_replace problem
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 |
eregi_replace problem
|
|
|
| why will this not work?
$source = eregi_replace('+44','0',$source);
| |
| Shane Lahey 2004-05-26, 9:31 pm |
| On Thu, 27 May 2004 00:45:13 +0100, "Brian" <not@given.com> wrote:
>$source = eregi_replace('+44','0',$source);
the + character needs to be escaped in regexp's
should be:
$source = eregi_replace('\+44', '0', $source);
| |
| Chris Hope 2004-05-26, 9:31 pm |
| Brian wrote:
> why will this not work?
>
> $source = eregi_replace('+44','0',$source);
+ has special meaning in regular expressions so you need to escape it with a
backslash for it to be taken literally as a plus symbol and so your regexp
will work, eg:
$source = eregi_replace('\+44','0',$source);
--
Chris Hope
The Electric Toolbox - http://www.electrictoolbox.com/
| |
|
| DOH!!!
It's been a long day, I should have seen that one, thanks guys :)
(time for bed me thinks, it's late and been programming all day)
Brian
>
> + has special meaning in regular expressions so you need to escape it with
a
> backslash for it to be taken literally as a plus symbol and so your regexp
> will work, eg:
>
> $source = eregi_replace('\+44','0',$source);
>
> --
> Chris Hope
> The Electric Toolbox - http://www.electrictoolbox.com/
| |
|
| if you don't need the power of regular expressions use str_replace:
$source = str_replace('+44', '0', $source);
but if you do need to use regular expressions, use preg_replace (faster than
ereg...):
$source = preg_replace('/\+44/', '0', $source);
"Brian" <not@given.com> wrote in message
news:Kbbtc.162$YT4.43@newsfe5-win...
> DOH!!!
>
> It's been a long day, I should have seen that one, thanks guys :)
> (time for bed me thinks, it's late and been programming all day)
>
> Brian
>
with[color=darkred]
> a
regexp[color=darkred]
>
>
|
|
|
|
|