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

    Join Date
    Jul 2004
    Rep Power

    Question How to eliminate some string using regex?

    My curl function returned some html tags and part of it was :

    <span class="descBold">1<span class="null">9999</span>2<span class="null2">8888</span><span class="null3">7777</span><span class="null4">5555</span><span class="notnull">3</span></span>

    given the above tags i want to get as output the numbers highlighted as bold (123), and eliminate or ignore other numbers that uses the span with classes like "null", "null2", "null3" and "null4".

    Can some one here help me with this problem?

    Kind Regards,
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Pennsylvania, USA
    Rep Power
    Since your HTML is so weirdly formed, I couldn't find a decent way to do this with a pure regexp. Here's a PHP implementation:
    PHP Code:
    $string '<span class="descBold">1<span class="null">9999</span>2<span class="null2">8888</span><span class="null3">7777</span><span class="null4">5555</span><span class="notnull">3</span></span>';
    preg_match_all("/<span( class=['\"](.+?)['\"])?>([^<]+)/"$string$foo);
    foreach ( 
    $foo[2] AS $key => $className ) {
        if ( 
    substr($className04) != 'null' ) {
    $foo[3][$key] . "\n";

    Outputs 1 and 3

    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