note 47845 added to function.fsockopen

From: Date: Thu, 02 Dec 2004 13:50:54 +0000
Subject: note 47845 added to function.fsockopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-81275@lists.php.net to get a copy of this message
Here's a function to just fetch the contents behind an URL. <?php function fetchURL( $url ) { $url_parsed = parse_url($url); $host = $url_parsed["host"]; $port = $url_parsed["port"]; if ($port==0) $port = 80; $path = $url_parsed["path"]; if ($url_parsed["query"] != "") $path .= "?".$url_parsed["query"]; $out = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n"; $fp = fsockopen($host, $port, $errno, $errstr, 30); fwrite($fp, $out); $body = false; while (!feof($fp)) { $s = fgets($fp, 1024); if ( $body ) $in .= $s; if ( $s == "\r\n" ) $body = true; } fclose($fp); return $in; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.fsockopen.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47845 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47845&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47845&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47845&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47845&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47845&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47845&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47845&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81275) next »