Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    66
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Can PHP read an HTML page?

    It may sound kind of crazy, but I'm trying to see if there's a way php code can 'read' contents of a static HTML page and store the contents into a variable.

    Is it possible? If so, how?

    For example,

    1. PHP reads http://anysite.com/anypage.html

    2. PHP stores all contents of that page into a variable.

    Thanks for your help!

    Elliott
    http://projectvibe.net

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    I think they call it curl.
    http://us3.php.net/curl

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts

  • #4
    New Coder
    Join Date
    Sep 2006
    Posts
    66
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Thanks for the reply... and it works... sort of.

    See the URL where i'm trying to get contents from is actually a windows media publishing point.. so there is no visible 'file' in the url.

    The url is http://212.72.165.21:8000/projectvibe/

    is there a way to get contents of this url?

    Thanks,

    Elliott
    http://projectvibe.net

  • #5
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    PHP Code:
    <?php
    get_file_contents
    ("http://212.72.165.21:8000/projectvibe/");
    ?>

  • #6
    Regular Coder
    Join Date
    Feb 2007
    Location
    Canada
    Posts
    924
    Thanks
    10
    Thanked 56 Times in 55 Posts
    Good tunes, thanks.

  • #7
    New Coder
    Join Date
    Sep 2006
    Posts
    66
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rafiki View Post
    PHP Code:
    <?php
    get_file_contents
    ("http://212.72.165.21:8000/projectvibe/");
    ?>
    I already tried that (including the url) and unfortunately it doesn't work. It waits for a few seconds and produces a blank page.

  • #8
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,026
    Thanks
    2
    Thanked 315 Times in 307 Posts
    It does work for me -
    PHP Code:
    <?php
    $content 
    file_get_contents("http://212.72.165.21:8000/projectvibe/");
    echo 
    $content;
    ?>
    Either url_fopen is not enabled on your server or the site is not reachable from where you are attempting to do this.

    Either check your web server log for errors and/or put the following two lines in after your first opening <?php tag -
    PHP Code:
    ini_set ("display_errors""1");
    error_reporting(E_ALL); 
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •