PHP生成网页快照

<pre class="brush:php;toolbar:false">&lt;?php $url=&#39;www.baidu.com&#39;;//抓取百度 echosnapshot($url);//输出结果为图片地址 echosnapshot($url,&#39;./baidu.png&#39;);//将图片保存至本地baidu.png,输出内容图片大小 /** *生成网页快照 *FrPHP100.com论坛xiaokai *@paramstring$site目标地址 *@paramstring$path保存地址,为空则不保存 *@paraminteger$dealy延迟 *@returnmixed根据参数返回 */ functionsnapshot($site,$path=&#39;&#39;,$dealy=0) { $url=&#39;http://ppt.cc/yo2/catch.php&#39;; $query=&#39;url=&#39;.$site.&#39;&amp;delay=&#39;.$dealy.&#39;&amp;rnd=&#39;.mt_rand(1,9); $ch=curl_init($url); curl_setopt($ch,CURLOPT_POST,true); curl_setopt($ch,CURLOPT_POSTFIELDS,$query); curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER[&#39;HTTP_USER_AGENT&#39;]); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); $data=curl_exec($ch); curl_close($ch); if(strlen($data)!=32){ exit(&#39;无效网址&#39;); } $file=$data{0}.&#39;/&#39;.$data{1}.&#39;/&#39;.$data{2}.&#39;/&#39;; $file=&#39;http://cache.ppt.cc/&#39;.$file.&#39;src_&#39;.$data.&#39;.png&#39;; if(!empty($path)){ $data=file_get_contents($file); returnfile_put_contents($path,$data); } return$file; }</pre>
RangeTime:0.008576s
RangeMem:204.78 KB
返回顶部 留言