Reah HTML with PHP

Discussion in 'PHP' started by jumpenjuhosaphat, Aug 3, 2006.

  1. #1
    I was wondering how I could go about reading HTML documents on other sites using PHP. I have tried searching the internet and through some of the tutorials and references, and have found how to read XML, but nothing about HTML. Does anyone have any ideas how to do this, or where I can find out?

    Specifically, I would like to search other sites for certain tags and text, like anchor tags.
     
    jumpenjuhosaphat, Aug 3, 2006 IP
  2. rederick

    rederick Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Something like this ... simple but it's the general idea.


    <?php

    $file = file_get_contents("http://www.example.com");
    $pattern = "http:\/\/www\.example\.com";


    if (preg_match("/$pattern/",$file))
    echo "Good";
    else
    echo "Bad";


    ?>
     
    rederick, Aug 3, 2006 IP
  3. coderlinks

    coderlinks Peon

    Messages:
    282
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yea, you can use file_get_contents. But if your webhost has disabled this, you can use the cURL extensions. They are much more flexible and also support cool stuff like HTTPS and Proxies.

    http://php.net/curl

    Thomas
     
    coderlinks, Aug 4, 2006 IP