Re: regexp problem
| From: | Joe Stump | Date: | Sun, 17 Dec 2000 01:58:23 +0000 |
| Subject: | Re: regexp problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-30699@lists.php.net to get a copy of this message | ||
If all you want to do is replace a word with another use str_replace() - it's
quite a bit faster and just the same thing.
$new_string = str_replace('the','foo',$old_string);
--Joe
On Sun, Dec 17, 2000 at 01:56:55AM +0000, Chris Jones wrote:
> Hi
>
> I'm working on simple regexp that works fine with sed, but doesn't seem
> to work with PHP 4.0.3pl1.
>
> For example, I want to replace all occurances of the word "the" with
> "foo", so I use:
>
> cat file.txt | sed -e "s/\Wthe\W/ foo /g"
>
> and it works. Translating this into php would be:
>
> print (egrep_replace ("\Wthe\W", " foo ", $text));
>
> but this just produces the original $text with nothing changed. What am I
> doing wrong?
>
> Many thanks,
> --
> _____ _ _ _____
> | __ | |___ ___| |_ ___| __|_ _ ___ Chris "Ng" Jones
> | __ -| | .'| _| '_|___|__ | | | | chris@black-sun.co.uk
> |_____|_|__,|___|_,_| |_____|___|_|_| www.black-sun.co.uk
> S o f t w a r e
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
---
Joe Stump
PHP Programmer
www.Care2.com