PHP怎么获取指定网页源码?

WBOY
Release: 2016-06-23 14:09:36
Original
1747 people have browsed it

PHP怎么获取指定网页源码?
我用了file, file_get_contents, curl等方法,发现只能打开自己网站的源码,别的网站baidu.com sina.com.cn统统都获取不了。。不知道是怎么回事

比如用的 file_get_contents,下面这样应该是能成功的啊。。怎么我一试就不行。。
$str = file_get_contents($url);

另外服务器php.ini是打开了allow_url_fopen的。。


回复讨论(解决方案)

那得到的是什么呢?

那得到的是什么呢?
什么都没有啊。。。

那么你
echo file_get_contents('http://bbs.csdn.net/topics/390455646?page=1#post-394461296');

都能看到什么?

那么你
echo file_get_contents('http://bbs.csdn.net/topics/390455646?page=1#post-394461296');

都能看到什么?

什么都没有。。拿strlen取长度也是0。。。

我用的Awardspace上的虚拟空间主机。。是不是除了allow_url_fopen有什么会限制读取?

可能是有些限制吧,用 phpinfo() 看看

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!