这里有新鲜出炉的 PHP 面向对象编程,程序狗速度看过来!
PHP(外文名: Hypertext Preprocessor,中文名:"超文本预处理器")是一种通用开源脚本语言。语法吸收了 C 语言、Java 和 Perl 的特点,入门门槛较低,易于学习,使用广泛,主要适用于 web 开发领域。PHP 的文件后缀名为 php。
这篇文章主要介绍了 php 基于 curl 重写 file_get_contents 函数的方法, 结合实例形式分析了 php 使用 curl 重写 file_get_contents 函数实现屏蔽错误提示的相关技巧, 需要的朋友可以参考下
本文实例讲述了 php 基于 curl 重写 file_get_contents 函数。分享给大家供大家参考,具体如下:
file_get_contents 在连接不上的时候会提示 Connection refused,有时候会带来不便;另外,curl 的性能比 file_get_contents 高,所以用 curl 重写 file_get_contents
- function _file_get_contents($s) {
- $ret = "";
- $ch = curl_init($s);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
- curl_setopt($ch, CURLOPT_TIMEOUT, 0);
- $buffer = curl_exec($ch);
- curl_close($ch);
- if ($buffer === false || empty($buffer)) {
- $ret = "";
- } else {
- $ret = $buffer;
- }
- return $ret;
- }
希望本文所述对大家 PHP 程序设计有所帮助。
来源: http://www.phperz.com/article/17/0804/341409.html