Parsing a webpage in PHP

Discussion in 'PHP' started by seofast, Jun 30, 2010.

  1. #1
    I'm working on a project in which i need to extract <img> tags and their <alt> tags from a html page using PHP code. There are many imagess in the
    html page and i have to write the code in such a way that it extracts the image and its alt tag from that html page.

    Can anyone help me in
    this?
    If anyone has a code for it please say it to me.

    Thankx
     
    seofast, Jun 30, 2010 IP
  2. Michellu

    Michellu Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    To get all img tags from your text use:
    preg_match_all('/<img(.*)>/U', $str, $out);
    PHP:
    You will get the results in $out array (you will actually get two sets of arrays: one with all between <img and the next > including these delimiters, and one set with the text between <img and the next > excluding these delimiters.
     
    Michellu, Jun 30, 2010 IP