1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

regexe pattern matching

Discussion in 'PHP' started by piyu75, Feb 24, 2008.

  1. #1
    I have a file that has repeated pattern of following.

    <table id=ABCd009 class=x100>
    <tr style='cursor:pointer' onclick='On(97508054)'>
    <td class=myclass><img src=/i/image.gif></td>
    <td class='head x100' style='background-color:#f8fbff'>This is a test of my programming skiils and i was found to be dumb <B class=h5>dumb </B>I am ashamed.
    </td>
    </tr>
    </table>

    I am trying to use preg_match_all to find if there was a keyword "skiils" in
    <td class='head x100' style='background-color:#f8fbff'>This is a test of my programming skiils and i was found to be dumb <B class=h5>dumb </B>I am ashamed.
    </td>
    I have tried several combination of pattern that I think should return the match but nothing works. This is the one i tried last but nosuccess.
    $Key_RE = "(<td.*>).*(skiils).*(</td>)";

    Can anybody help me making that pattern string
     
    piyu75, Feb 24, 2008 IP
  2. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?
    $html = <<< HTML
    <table id=ABCd009 class=x100>
    <tr style='cursor:pointer' onclick='On(97508054)'>
    <td class=myclass><img src=/i/image.gif></td>
    <td class='head x100' style='background-color:#f8fbff'>This is a test of my programming skiils and i was found to be dumb <B class=h5>dumb </B>I am ashamed.
    </td>
    </tr>
    </table>
    HTML;
    
    $html = strip_tags($html, "<td>");
    
    preg_match_all("/<td(?:[^>]*)>(?:[^<]*)(skiils)(?:[^<]*)<\/td>/i", $html, $matches);
    header("Content-type: text/plain");
    print_r($matches);
    ?>
    PHP:
    Prints:
    Array
    (
        [0] => Array
            (
                [0] => <td class='head x100' style='background-color:#f8fbff'>This is a test of my programming skiils and i was found to be dumb dumb I am ashamed.
    </td>
            )
    
        [1] => Array
            (
                [0] => skiils
            )
    
    )
    Code (markup):

    Yes, I had it strip all the other HTML tags first. You get the idea.
     
    zerxer, Feb 24, 2008 IP