note 63843 deleted from function.file-get-contents by nlopess

From: Date: Sun, 16 Apr 2006 22:33:45 +0000
Subject: note 63843 deleted from function.file-get-contents by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-108291@lists.php.net to get a copy of this message
Note Submitter: MrLucky ---- I wrote a function that can get the contents of a url through foskcopen() <?php /* * @desc get the contents of a url through fsockopen() * @param IP * @param Port number * @param file * @param timeout * @param add headers to result? * @return the contents with or without headers */ function sock_get_contents($ip, $port, $file, $timeout, $header = false) { $request = "GET ".$file." HTTP\1.0\r\n\r\n"; $return = ''; $sock = fsockopen($ip, $port, $err_no, $err_str, $timeout); if(is_resource($sock)) { fputs($sock, $request); if($header == false) { $line = ""; while(!($line == "\r\n")) { $line = fgets($sock, 128); if(preg_match("#Location\: (.*?)\\r\\n#si", $line, $matches)) { return sock_get_contents($ip, $port, "/".$matches[1], $timeout, $header); } } // strip out the header } while ($buffer = fgets($sock, 4096)) { $return .= $buffer; } fclose($sock); return $return; } else { return false; } } ?>

« previous php.notes (#108291) next »