#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    178
    Rep Power
    205

    Find any html tag in the string


    Hi,

    I have strings like

    1 - blah blah blah <strong>htmlgoes</strong> {p}xxxx{/p}
    2 - blah blah blah {p}<p>this one is ok{/p}
    3 - <a href=''>wrong</a>


    these strings are matched one by one in a loop. I want to match all strings that are using html tags BEFORE first occurence of {p}. if an HTML tag is used within {p} then that is fine, but it should not be used before the first occurence of {p} ALSO {p} is optional, it can either be in a string or not.

    so in above only #2 string is correct, and I have to match 1,3 as incorrect

    I tried something like
    Code:
    /<[^.*?>(.*?)(\{p\})?/is
    
    /<[^.*?>(.*?)(?!\{p\})/is


    but that is giving me weird results

    any help is much appreciated.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,128
    Rep Power
    9398
    1. Get the location of the first {p}
    2. Get the location of the first HTML tag
    3. If there is a {p} and the HTML tag comes before it the string is invalid
    Beyond that I'm not sure what you want.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    178
    Rep Power
    205
    yeah that's exactly what I am trying to do. As I showed the two regex I tried. none of them work. do you have any idea how to make it work? I am using them in preg_match()
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    Requinix is saying to do it using string-manipulation functions in your code, not to use regular expressions.

    -Dan
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo