php采用file_get_contents代替使用curl实例

yipeiwu_com5年前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页面运行时间的函数介绍

一个计算php页面运行时间的函数。复制代码 代码如下:<?php/*@ 计算php程序运行时间*/function microtime_float(){list($usec, $s...

PHP中strtr字符串替换用法详解

本文实例讲述了PHP中strtr字符串替换用法。分享给大家供大家参考。具体分析如下: strtr(string,from,to)或者strtr(string,array) 首先针对str...

php pdo oracle中文乱码的快速解决方法

在/etc/profile.d/简历oracle.sh 内容如下在NLS_LANG设置编码 ORACLE_HOME=/usr/lib/oracle/12.1/client64 C_I...

真正的ZIP文件操作类(php)

<? /******************** 作者未知 整理: Longbill ( www.longbill.cn ; lo...

php站内搜索关键词变亮的实现方法

本文实例讲述了php站内搜索关键词变亮的实现方法。分享给大家供大家参考。具体分析如下: 我们这个做法是把搜索结果出来,与搜索关键词相同的替换成高亮的字, 我们会用到str_replace...