Getting Contents of a Webpage

Discussion in 'PHP' started by KevinJB, Aug 8, 2006.

  1. #1
    I'm pretty sure there is a function to do this already but Google was absolutely no help what-so-ever. I just need something that will return a string containing the contents of a webpage (the HTML basically). How would I go about doing this, or does anyone know how what the built-in function is (if there is one)?
     
    KevinJB, Aug 8, 2006 IP
  2. KevinJB

    KevinJB Peon

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Wow, I need to wait a bit before I go begging for help. After much searching through the PHP documentation I found the function's name is 'file_get_contents(string url)', in case anyone else is wondering.
     
    KevinJB, Aug 8, 2006 IP
  3. smatts9

    smatts9 Active Member

    Messages:
    1,089
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    88
    #3
    Are the owners of this content your looking to scrape allowing you to do so?
     
    smatts9, Aug 8, 2006 IP
  4. coderlinks

    coderlinks Peon

    Messages:
    282
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can also use the curl functions. It supports proxies and HTTPS too.
    http://php.net/curl

    Thomas
     
    coderlinks, Aug 8, 2006 IP
    KevinJB likes this.
  5. 1EightT

    1EightT Guest

    Messages:
    2,646
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    0
    #5
    snoopy will do it too
     
    1EightT, Aug 8, 2006 IP
  6. Edynas

    Edynas Peon

    Messages:
    796
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #6
    fopen and fread will do the trick too.
    
    
    $filename = "url";      // Location of the News Source 
    $start = "code where you want to begin";      // Start Grabbing Code 
    $stop  = "code where to stop";                 // Stop Grabbing Code 
    
      // Get contents of the specified URL and writes it into a string 
    $fd = fopen( $filename, "r" ); 
    $contents = fread( $fd, 50000 ); 
    fclose( $fd ); 
    
      // Isolates desired section. 
    if(eregi("$start(.*)$stop", $contents, $printing)) { 
      $substring=$printing[1]; 
      
    
      // while is added as there are multiple instances of the start en stop string & eregi 
      // searches to include the most that matches, not the next. 
     while(eregi("(.*)$stop", $substring, $printing)) { 
         $substring=$printing[1]; 
        
       };
    
    
    PHP:
     
    Edynas, Aug 9, 2006 IP
    KevinJB likes this.
  7. KevinJB

    KevinJB Peon

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Where did I say I was scraping content? :confused: Don't assume things about people you don't know.

    Thanks everybody else for the helpful responses, green rep well earned :)
     
    KevinJB, Aug 9, 2006 IP