Re: str_replace
From: Bruno Desthuilliers (bdesth.quelquechose_at_free.quelquepart.fr)
Date: 04/13/04
- Next message: .: DeVa :.: "Re: dynamic thumbnailing ?"
- Previous message: John Pastrovick: "Re: SQL syntax to update records with diff'rent function generated random PINS"
- In reply to: Alexander Ross: "str_replace"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 13 Apr 2004 11:00:16 +0200
Alexander Ross wrote:
> I have a sting var that contains some simple html:
>
> $haystack = "This test is a <a href='test.html'>test</a>";
>
> I want to replace all occurences of the word "test" with the word "bob" IF
> AND ONLY IF "test" is not found in an anchor tag (or not immediately
> followed by "</a>")
>
> $needle = " test";
> $replaceNeedleWith = "bob";
>
>
> // function str_replace_unless($haystack,$needle,$replaceNeedleWith )
>
> How could i do this?
>
> Alex
>
>
With a regular expression ( -> preg_replace). A simple string search and
replace won't do it.
Bruno
- Next message: .: DeVa :.: "Re: dynamic thumbnailing ?"
- Previous message: John Pastrovick: "Re: SQL syntax to update records with diff'rent function generated random PINS"
- In reply to: Alexander Ross: "str_replace"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|