php采用file_get_contents代替使用curl实例

yipeiwu_com6年前PHP代码库

本文实例讲述了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 时间转换Unix时间戳代码

复制代码 代码如下:<?php date_default_timezone_set('Asia/Chongqing'); $time1 = "2006-04-16 08:40:54...

PHP中的正则表达式函数介绍

正则表达式(Regular Expression) 正则表达式系统:   1.POSIX   2.Perl PHP中使用的regex是PCRE:   NOTE:PCRE(Perl兼容正则...

PHP中spl_autoload_register()函数用法实例详解

本文实例分析了PHP中spl_autoload_register()函数用法。分享给大家供大家参考,具体如下: 在了解这个函数之前先来看另一个函数:__autoload。 一、__aut...

php实现模拟登陆方正教务系统抓取课表

课程格子和超级课程表这两个应用,想必大学生都很熟悉,使用自己的学号和教务系统的密码,就可以将自己的课表导入,随时随地都可以在手机上查看。   其实稍微了解一点php的话,我们也可以做一个...

PHP常用技巧总结(附函数代码)

PHP文件读取函式 复制代码 代码如下: //文件读取函式 function PHP_Read($file_name) { $fd=fopen($file_name,r); while(...