Re: preg_replace problem
| From: | Stefan Dengscherz | Date: | Tue, 17 Jun 2003 12:13:28 +0000 |
| Subject: | Re: preg_replace problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-151824@lists.php.net to get a copy of this message | ||
Hello,
<?php
$parsed =
preg_replace("/(\ba\b)/i","<tag>\\1</tag>",$sourcestring);
?>
should do the job.
regards
Am Die, 2003-06-17 um 13.25 schrieb Vincent Bouret:
> Hi,
>
> I am having this problem with preg_replace. I want the following thing but I
> can't understand what regular expression I should put.
>
> I want to replace all occurences of a given **whole** word into a string.
>
> For example:
>
> I want "A dog jumped over a ladder" to become "<xyz>A</xyz> dog
> jumped over
> <xyz>a</xyz> ladder".
>
> I **don't** want: "A dog jumped over a ladder" to become
> "<xyz>A</xyz> dog
> jumped over <xyz>a</xyz> l<xyz>a</xyz>dder".
>
> You understand what I mean? I can't do that will str_replace, but I know it
> would be quite easy with preg_replace. Can someone help me?
>
> Thanks
>
> Vincent
>
>
>