Need Help with this RegExp

Discussion in 'Programming' started by GeoffreyF67, Dec 12, 2006.

  1. #1
    I've got the following text:

    </div>
                 <div id="tags">
           <div class="tagsRight"> <a href="/tags/spiderman/">Spiderman</a> <a href="/tags/3/">3</a> <a href="/tags/trailer/">Trailer</a> </div>
           <span class="tagsT">Tags:</span>
           </div>
    Code (markup):
    And I want to get the anchor text out of each of those in an array. I.E. Spiderman, 3, Trailer

    I'm trying to do a preg_match_all in php with this but I can't get the regular expression to work.

    Any ideas would help.

    G-Man
     
    GeoffreyF67, Dec 12, 2006 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    
    <?
    $content ='
    </div>
                 <div id="tags">
           <div class="tagsRight"><a href="/tags/spiderman/">Spiderman</a> <a href="/tags/3/">3</a> <a href="/tags/trailer/">Trailer</a> </div>
           <span class="tagsT">Tags:</span>
           </div>
    ';
    
    preg_match_all("/<a.*?>(.*?)<.*?>/", $content, $matches);
    
    echo "<pre>";
    print_r($matches);
    
    PHP:
     
    krakjoe, Dec 12, 2006 IP