Regex to get anchor text

Discussion in 'PHP' started by blake3334, Feb 21, 2012.

  1. #1
    <A HREF=results.asp?blah=00000-000-000>00000-000-000</A>
    How to get anchor text when href contains this text 'results.asp?blah=' and the text after 'blah='
     
    blake3334, Feb 21, 2012 IP
  2. blake3334

    blake3334 Member

    Messages:
    407
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #2
    Actually better yet I need a regex that finds a parcel number like 00-00-00-0000-0000-0000 or 00000-000-000
     
    blake3334, Feb 21, 2012 IP
  3. Lee Stevens

    Lee Stevens Active Member

    Messages:
    148
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    68
    #3
    Hope this helps you :)

    
    $regex = "<a(.*?)href=(.*?)>(.*?)</a>";
    
    PHP:
     
    Lee Stevens, Feb 22, 2012 IP
  4. ker

    ker Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Once you get anchor link use parse_url to get query string (?*).

    <?php
    $url = 'http://username:password@hostname/path?arg=value#anchor';
    $url = preg_match('/<a href="(.+)">/', $html, $match);
    $info = parse_url($match[1]);
    echo $info['query'];
    ?>
    PHP:
     
    ker, Feb 22, 2012 IP