help need for preg_match_all()

Discussion in 'PHP' started by sudip03, Jun 26, 2010.

  1. #1
    i need to fetch the text in H1 tag from a website source code. Now i can make a .txt file and store the source code over there then search the required field. for this i think preg_match_all() is the best function for searching.
    Now the problem is that the arguments of this function is really sucking me. If anyone can help me out then it will be really cool.
     
    sudip03, Jun 26, 2010 IP
  2. Kaimi

    Kaimi Peon

    Messages:
    60
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    preg_match_all('/<h1>(.+?)<\/h1>/i', $website_source_code, $match);
    print_r($match);
     
    Kaimi, Jun 26, 2010 IP
  3. sudip03

    sudip03 Peon

    Messages:
    155
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thangs a lot u have really solved my problem. But one thing still i need to know that suppose i want to fetch the H1 tag which is having a class like (<h1 class="not known">to be fetched</h1>) . So in this case how can i tackle the class name out of the search query and fetch the h1 tag.
     
    Last edited: Jun 26, 2010
    sudip03, Jun 26, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    preg_match_all('/<h1 class="[^"]+">(.+?)<\/h1>/i', $website_source_code, $match);
    print_r($match);
    PHP:
     
    danx10, Jun 26, 2010 IP
  5. sudip03

    sudip03 Peon

    Messages:
    155
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    cool dude your help has made my job easier. Thanks a lot and thumbs up to you. keep up
     
    sudip03, Jun 26, 2010 IP