SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Serbia
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A variable inside regexp pattern

    I want to have a php variable inside my regexp pattern, something like:

    PHP Code:
    $body htmlentities(preg_replace("/(<font color="$font_color">)([^<>\w\W]*)(<\/font>)/i"""$matches1[0])); 
    It won't work this way.

    Is that possible at all?

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think you need to escape the strings try this
    PHP Code:
     $body htmlentities(preg_replace("/(<font color=\"$font_color\">)([^<>\w\W]*)(<\/font>)/i"""$matches1[0])); 
    Note: its not tested

  3. #3
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you suppose this would match?

    [^<>\w\W]*

    I'm pretty sure that says don't match anything that is a word character or a non-word character. That doesn't leave much

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Serbia
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First I made it so that all comments in the body of html document are deleted:

    PHP Code:
    $body htmlentities(preg_replace("/(<!--)([\w\W]*)(-->)/i"""$matches1[0])); 
    Next I have to delete all occurences of <font color="$font_color">.......</font> inside $body.

    So how would I match all occurences of

    <font color="FFFFFF">some_text_here</font>

    or

    <font color="$font_color">some_text_here</font>

    and replace that with empty space?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •