Jump to content

Php Function To Read And Return The Page Content Of A Given Url


eliza81

Recommended Posts

Here is a function which will help you to read the page content of a given link and return the data in an array. So that you can use the data as per your requirement. /** FUNCTION TO RETURN PAGE CONTENT OF GIVEN URL****/ public function HttpRequest( $url, $method = 'GET', $data = NULL, $additional_headers = NULL, $followRedirects = true ) { $method = strtoupper($method); /************************/ /*Parse the given url */ /***********************/ $url_parsed = @parse_url($url); if (!@$url_parsed['scheme']) $url_parsed = @parse_url('http://'.$url); /******************************************************************/ /*Extract the parseed url values */ /*It will get the variables $scheme,$host,$port,$user,$pass,$path,$query,$fragment */ /****************************************************************/ extract($url_parsed); /***********************************************************/ /*Check if any data is there to post along with the url */ /**********************************************************/ if(!is_array($data)) { $data = NULL; }else{ $ampersand = ''; $temp = NULL; foreach($data as $k => $v) { $temp .= $ampersand.urlencode($k).'='.urlencode($v); $ampersand = '&'; } $data = $temp; }

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...