Get html code with php

Discussion in 'PHP' started by shotazi, Nov 30, 2007.

  1. #1
    So i want to get content from some link with php

    i try this:
    <?php
    // For PHP 5 and up
    $handle = fopen("http://www.example.com/", "rb");
    $contents = stream_get_contents($handle);
    fclose($handle);
    ?> 
    PHP:
    and this:
    <?php
    $handle = fopen("http://www.example.com/", "rb");
    $contents = '';
    while (!feof($handle)) {
      $contents .= fread($handle, 8192);
    }
    fclose($handle);
    ?> 
    PHP:
    but they doesn't works :( please help me
     
    shotazi, Nov 30, 2007 IP
  2. bobb1589

    bobb1589 Peon

    Messages:
    289
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    it works for me... what is the problem you are having?
     
    bobb1589, Nov 30, 2007 IP
  3. shotazi

    shotazi Peon

    Messages:
    422
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i have this code:
    <?php
    // For PHP 5 and up
    $handle = fopen("http://www.google.com/", "rb");
    $contents = stream_get_contents($handle);
    fclose($handle);
    ?>
    here: http://nonagame.com/oo.php , you can see there is this error:
    Fatal error: Call to undefined function: stream_get_contents() in /home/www/nonagame.com/oo.php on line 4
     
    shotazi, Nov 30, 2007 IP
  4. shotazi

    shotazi Peon

    Messages:
    422
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hey can anybody help me?

    :(
     
    shotazi, Nov 30, 2007 IP
  5. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #5
    Fatal error: Call to undefined function: stream_get_contents() in /home/www/nonagame.com/oo.php on line 4

    The line above means you dont have the function in your setup, i think that function is only available on PHP5 are you sure you are using php5?
     
    serialCoder, Nov 30, 2007 IP
  6. shotazi

    shotazi Peon

    Messages:
    422
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i don't know but is there any other function about this?
     
    shotazi, Nov 30, 2007 IP
  7. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #7
    you can probably try and use file_get_contents() instead
     
    serialCoder, Nov 30, 2007 IP
  8. shotazi

    shotazi Peon

    Messages:
    422
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    i wrote this code
    <?php
    $handle = file_put_contents("http://www.google.com/");
    echo $handle;
    ?>
    but there is error

    Fatal error: Call to undefined function: file_put_contents() in /home/www/nonagame.com/oo.php on line 2
     
    shotazi, Nov 30, 2007 IP
  9. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #9
    please look carefully at the function, its file_get_contents()
     
    serialCoder, Nov 30, 2007 IP
  10. shotazi

    shotazi Peon

    Messages:
    422
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #10
    yea it is working thank you very much :)
     
    shotazi, Nov 30, 2007 IP