Re: question about str_replace()
| From: | Monte Ohrt | Date: | Wed, 26 Jul 2000 15:54:51 +0000 |
| Subject: | Re: question about str_replace() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-8329@lists.php.net to get a copy of this message | ||
If you want to replace all words beginning with "good", you can use pcre's word
boundary (\b) feature.
echo preg_replace("/\bgood(\w)*/","blah",$sentence);
This will replace words like:
good
goody
goodman
it will not replace words like:
mygood
ohgoody
It will also find boundaries correctly, so if "good" is immediately preceded by
non-word characters, it will still match.
Jeroen Wesbeek wrote:
> this works just fine:
>
> <?php
> $sentence = "good things are not as bad as less good things...";
> $word = "good";
> $newword = "bla";
>
> echo ereg_replace("^".$word,$newword,$sentence);
>
> ?>
>
> Greetings,
>
> Jeroen Wesbeek
> Webdeveloper
> DoWebWeDo
> St. Jacobsstraat 16
> 3500 AK Utrecht
>
> 030-2348110
>
> [ Roses are red, violets are blue, I am schizophrenic and so
> am I ]
> [ If you don't understand it, get rid of it ]
>
> -----Original Message-----
> From: xinkun wang [mailto:xinkun_wang@hotmail.com]
> Sent: woensdag 26 juli 2000 17:24
> To: php-general@lists.php.net
> Subject: [PHP] question about str_replace()
>
> Dose anybody know if I want to replace the word which exactly begin with the
>
> word and maybe have some postfix changing. For instance I want to replace
> "good", "goodes", "goodbye" to new words, but not change
> "togood".
> I use
> $word="good";
> $ins="^".$word;
> str_place($ins,"newword",$line);
> but it does not work, any ideas?
>
> please reply this email.
> ________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at
> http://www.hotmail.com
>
> --
> 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
>
> --
> 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