<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[阿Tim日志]]></title> 
<link>https://atim.cn/index.php</link> 
<description><![CDATA[专业的php开发者.开发团队的带队人]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[阿Tim日志]]></copyright>
<item>
<link>https://atim.cn/post//</link>
<title><![CDATA[用curl读远程地址]]></title> 
<author>bkkkd &lt;partybase@gmail.com&gt;</author>
<category><![CDATA[开发应用]]></category>
<pubDate>Mon, 06 Feb 2006 10:49:58 +0000</pubDate> 
<guid>https://atim.cn/post//</guid> 
<description>
<![CDATA[ 
	function getHeader($content)<br/>&#123;<br/> $array = preg_split("/(\r\n?)/", $content, 2);<br/> if (!isset($array[1])) $array[1] = null;<br/> return $array;<br/>&#125;<br/><br/>//$url 要读取的地址,$allowExts 如果有跳转,允许跳转后的扩展名<br/>function read($url, $allowExts, $header = true)<br/>&#123;<br/> $ch = curl_init();<br/> <br/> curl_setopt($ch, CURLOPT_URL, $url);<br/> curl_setopt($ch, CURLOPT_HEADER, $header);<br/> curl_setopt($ch, CURLOPT_FAILONERROR, true);<br/> curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br/> curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);<br/> curl_setopt($ch, CURLOPT_USERAGENT, "PHP WORLD Spider - WWW.PHPWORLD.CN");<br/> <br/> if ($header == true)<br/> &#123;<br/> &nbsp;$m = getHeader(curl_exec($ch)); <br/> &#125;<br/> else <br/> &#123;<br/> &nbsp;$content = curl_exec($ch); <br/> &nbsp;curl_close($ch);<br/> &nbsp;return $content;<br/> &#125;<br/><br/> <br/> //截取内容<br/> $header = $m[0];<br/> $body = $m[1];<br/> <br/> if (preg_match("/\nlocation:(.+)/", $header, $ar))<br/> &#123;<br/> &nbsp;$url = trim($ar[1]); <br/> &nbsp;$infos = @pathinfo(basename($url));<br/> &nbsp;if (isset($infos["extension"]) && in_array(strtolower($infos["extension"]), $allowExts))<br/> &nbsp;&#123;<br/> &nbsp; curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);<br/> &nbsp; curl_setopt($ch, CURLOPT_HEADER, $header);<br/> &nbsp; $content = curl_exec($ch); <br/> &nbsp; curl_close($ch);<br/> &nbsp; return $content;<br/> &nbsp;&#125;<br/> &#125;<br/> <br/> return $body;<br/>&#125;<br/><br/>echo read("http://www.test.com/a.php", array("php"));<br/><br/>
]]>
</description>
</item><item>
<link>https://atim.cn/post//#blogcomment</link>
<title><![CDATA[[评论] 用curl读远程地址]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://atim.cn/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>