Re: question about str_replace function
| From: | Jochem Maas | Date: | Mon, 08 Jan 2007 10:35:06 +0000 |
| Subject: | Re: question about str_replace function | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-246750@lists.php.net to get a copy of this message | ||
Dick Jiang wrote:
> I think you'd better use regular expression to replace the word
agreed - only it a serious dive in the deep end of regexps - the OP may
have to use a negative lookahead assertion, something like:
$string="avenue 1, ave 1 both have av+e :-)";
$words = preg_replace("#\\bave(?!nue)#", "avenue", $string);
>
> Regards,
> Dick
> -----Original Message-----
> From: Kencana [mailto:bluesky_dyx@hotmail.com]
> Sent: Monday, January 08, 2007 5:12 PM
> To: php-general@lists.php.net
> Subject: [PHP] question about str_replace function
>
>
> Hi all,
>
> I got a doubt about the str_replace function.
>
> <?php
> $string="avenue 1, ave 1";
> $words=str_replace ("ave","avenue", $string);
> echo $words;
> ?>
>
> the php code above will return me "avenuenue 1, avenue 1". i expect the
> result will be "avenue 1, avenue 1". any idea of how can i get such result?
>
> Thank you
>
> Regards,
> Kencana
>