如何才能正确的实现可为什么php抓取网页内容后没反应呢?连测试的文字都没有,要是我把echo 测试一下;放到第一行就可以输出,我估计是curl_init()函数还没有运行!
你看看php的phpinfo()中有没有curl扩展支持!
把php_curl.dll拷到c:windows和c:windowssystem32里面 重启apache之后再试试看
不是php_curl.dll这个文件,是把php目录中的libeay32.dll,ssleay32.dll拷到c:windowssystem32里面 重启apache
为了服务器安全着想,所以把allow_url_fopen关掉了。
当服务器allow_url_fopen = off 时,就不能用file_get_contents,只有设置on时可以用。
?php /* $getstr=file_get_contents(http://www.
163.com/weatherxml/54511.xml); $qx=explode(,strstr($getstr,qx=)); $wd=explode(,strstr($getstr,wd=)); $qximg=explode(,strstr($getstr,qximg=)); $qximg_=explode(,,$qximg[1]); echo 北京 .$qx[1].; echo $wd[1];*/ //echo img src='http://news.
163.com/img/logo/.$qximg_[0].'>
img src='http://news.163.com
/img/logo/.$qximg_[1].'>; ?>
以下php抓取网页内容的范例是通curl_init函数来获取163天气预报
把php.ini里( ;extension=php_curl.dll ) 前面的(;)去掉保存
把php_curl.dll,libeay32.dll,ssleay32.dll拷到c:windowssystem32里,重启iis即可,没有装apache
?php //初始化curl $ch = curl_init() or die (curl_error()); //设置url参数 curl_setopt($ch,curlopt_url,http:
//www.163.com/weatherxml/54511.xml); //要求curl返回数据 curl_setopt($ch,curlopt_returntransfer,1); //执行请求 $result = curl_exec($ch) or die (curl_error()); //取得返回的结果,并显示 //echo $result; // echo curl_error($ch); $qx=explode(,strstr($result,qx=)); $wd=explode(,strstr($result,wd=)); $qximg=explode(,strstr($result,qximg=)); $qximg_=explode(,,$qximg[1]); echo 北京 .$qx[1]. br />; echo $wd[1]; //关闭curl curl_close($ch); ?>
通过以上对php抓取网页内容的学习,大家可以自行实际操作一遍,加深对它的理解。
http://www.bkjia.com/phpjc/446179.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/446179.htmltecharticle如何才能正确的实现 可为什么php抓取网页内容后没反应呢?连测试的文字都没有,要是我把echo 测试一下;放到第一行就可以输出,我估计是...