代码: <?php /* 作者:blue2004 Date:2006-04-14 演示:http://weblog.chinahtml.com/163/?url=pearphp.com QQ :80392625 首发chinahtml,转贴和使用请保留这段信息 */ $hostname=$_GET['url']; if (!$hostname){ $hostname ="www.google.com"; } $url= "http://www.alexa.com/data/details/?url=$hostname"; $file =cached_fopen_url($url, "r", $timeout_seconds = 100, $cache_path = "./temp", $fsocket_timeout = 100); $files =explode("<span class=\"descBold\">",$file); $files1 =explode("</td><td class=\"paddingRight\" valign=\"top\">",$files[1]); $alexa =preg_replace ("'<[\/\!]*?[^<>]*?>'si", "", $files1[0]); echo $hostname.":".$alexa; function cached_fopen_url($url, $file_mode, $timeout_seconds = 90, $cache_path = "./temp", $fsocket_timeout = 100){ $debug = false; clearstatcache(); $cache_filename=$cache_path . "/" . urlencode($url) .".cached"; if ($debug) { print "local_cache creation_time =" . @filemtime($cache_filename) . " actual time = " . time() . " timeout = " . timeout_seconds ."<p>"; } if ( ( @file_exists($cache_filename ) and ( ( @filemtime($cache_filename) + $timeout_seconds) > ( time() ) ) ) ) { if ($debug) { print "using cached file ($cache_filename) <p>";} } else { if ($debug) { print "cacheing file ($url) to local ($cache_filename)<p>";} $urlParts = parse_url($url); $host = $urlParts['host']; $port = (isset($urlParts['port'])) ? $urlParts['port'] : 80; if( !$fp = @fsockopen( $host, $port, $errno, $errstr, $fsocket_timeout )) { } else { if( !fputs( $fp, "GET $url HTTP/1.0\r\nHost:$host\r\n\r\n" )) { die( "unable to send get request" ); } $data = null; stream_set_timeout($fp, $fsocket_timeout); $status = socket_get_status($fp); while( !feof($fp) && !$status['timed_out']) { $data .= fgets ($fp,8192); $status = socket_get_status($fp); } fclose ($fp); $sData = split("\r\n\r\n", $data, 2); $data = $sData[1]; $f2 = fopen($cache_filename,"w+"); fwrite($f2,$data); fclose($f2); } } if ( @file_exists($cache_filename )) { $handle = fopen($cache_filename, $file_mode); while (!feof($handle)) { $files .=fread($handle,8192); } } return $files; } ?>