Rumah  >  Artikel  >  pembangunan bahagian belakang  >  php采用file_get_contents代替使用curl实例,curlgetcontents_PHP教程

php采用file_get_contents代替使用curl实例,curlgetcontents_PHP教程

WBOY
WBOYasal
2016-07-13 10:14:49782semak imbas

php采用file_get_contents代替使用curl实例,curlgetcontents

本文实例讲述了php采用file_get_contents代替使用curl的方法,分享给大家供大家参考。具体实现方法如下:

file_get_contents代替使用curl其实不多见了,但有时你碰到服务器不支持curl时我们可以使用file_get_contents代替使用curl,下面看个例子。

当用尽一切办法发现 服务器真的无法使用curl时。或者curl不支持https时。curl https 出现502时。你又不想重装网站环境的时候,你就改用file_get_contents 代替吧。
curl 经常使用的 curl get curl post
curl get 替代 直接用file_get_contents($url) 就可以了
curl post 替代如下:

复制代码 代码如下:
function Post($url, $post = null) {      
        $content = http_build_query($post);
        $content_length = strlen($content);
        $options = array(
            'http' => array(
                'method' => 'POST',
                'header' =>"Content-type: application/x-www-form-urlencoded",
                'content' => $post
            )
        );
        return file_get_contents($url, false, stream_context_create($options));
}

希望本文所述对大家的php程序设计有所帮助。

php 用file_get_contents与curl都不可以获取内容

模拟个头部信息
array( 'method'=>"GET", 'header'=>"User-Agent: ".$_SERVER['HTTP_USER_AGENT']."\r\n" ) ); $context = stream_context_create($opts); $url = dynamic.12306.cn/...0$data = file_get_contents($url,null,$context);echo $data;?> 这样就可以了

 

用php 的 file_get_contents 或者curl (提出) 及echo (显示)

纯自动录入,还是配合人手动。假如手动就简单多了,无非就是写个正则把页

面的url和标题搞下来。要是纯自动的,你必须写一段程序模拟出来你正常访问

情况,当你到达第一页的时候,是发送的一个POST请求,你需要发送相应参数

和POST请求过去,然后再页面截取相应的需要,当要访问第二版的时候,发送

的是GET请求,这个时候同理要发送参数过去条状,直到第十页。php管网上有

类似的爬虫类,去下个,很方便的
 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/907835.htmlTechArticlephp采用file_get_contents代替使用curl实例,curlgetcontents 本文实例讲述了php采用file_get_contents代替使用curl的方法,分享给大家供大家参考。具体实...
Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn