Re: str_replace

From: Bruno Desthuilliers (bdesth.quelquechose_at_free.quelquepart.fr)
Date: 04/13/04


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



Relevant Pages

  • str_replace
    ... I have a sting var that contains some simple html: ... AND ONLY IF "test" is not found in an anchor tag (or not immediately ... Alex ...
    (comp.lang.php)
  • Re: [Newbie] Getting data from html-ish like crap.
    ... Which will get the whole document into the 'html' variable. ... regular expression are "capture groups", and they relate to the assignments ... Especially check out the 'Programming Ruby' book and read up Ruby's regular ... small, but usefull. ...
    (comp.lang.ruby)
  • Re: [Newbie] Getting data from html-ish like crap.
    ... joke generator that pulls the jokes off of a website. ... require 'net/http' ... Which will get the whole document into the 'html' variable. ... regular expression are "capture groups", and they relate to the assignments ...
    (comp.lang.ruby)
  • Re: Regular expression to structure HTML
    ... finesse a regular expression to build a substitution. ... What I'd like to do is extract data elements from HTML and structure ... triple-quote your multiline strings ...
    (comp.lang.python)
  • Re: Regular express for

    ,

      and
        tags
        ... Not only not a real language, Html is not a regular expression. ... Parsing Markup is considered to be the easiest thing in the world. ...
        (comp.lang.perl.misc)