四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

PHP 獲取遠(yuǎn)程文件內(nèi)容的函數(shù)代碼

如下函數(shù):
復(fù)制代碼 代碼如下:
<?
/**
獲取遠(yuǎn)程文件內(nèi)容
@param $url 文件http地址
*/
function fopen_url($url)
{
if (function_exists('file_get_contents')) {
$file_content = @file_get_contents($url);
} elseif (ini_get('allow_url_fopen') && ($file = @fopen($url, 'rb'))){
$i = 0;
while (!feof($file) && $i++ < 1000) {
$file_content .= strtolower(fread($file, 4096));
}
fclose($file);
} elseif (function_exists('curl_init')) {
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl_handle, CURLOPT_FAILONERROR,1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Trackback Spam Check'); //引用垃圾郵件檢查
$file_content = curl_exec($curl_handle);
curl_close($curl_handle);
} else {
$file_content = '';
}
return $file_content;
}
?>

相關(guān)解釋:
1,ini_get : Returns the value of the configuration option as a string on success, or an empty string on failure(讀取 php.ini 配置文件中的值)
2,; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
allow_url_fopen = On(配置文件中的內(nèi)容)
3,fopen( "rb"): 在操作二進(jìn)制文件時如果沒有指定 'b' 標(biāo)記,可能會碰到一些奇怪的問題,包括壞掉的圖片文件以及關(guān)于 /r/n 字符的奇怪問題。
注意: 為移植性考慮,強烈建議在用 fopen() 打開文件時總是使用 'b' 標(biāo)記。
注意: 再一次,為移植性考慮,強烈建議你重寫那些依賴于 't' 模式的代碼使其使用正確的行結(jié)束符并改成 'b' 模式。
4,strtolower -- Make a string lowercase
5,curl_init() :curl_init -- Initialize a cURL session(初始化一個cUrl會話)
resource curl_init ( [string url] )
Initializes a new session and return a cURL handle for use with the curl_setopt(), curl_exec(), and curl_close() functions.
url--If provided, the CURLOPT_URL option will be set to its value. You can manually set this using the curl_setopt() function.
Returns a cURL handle on success, FALSE on errors.
6,curl_setopt -- Set an option for a cURL transfer(提供設(shè)置)
bool curl_setopt ( resource ch, int option, mixed value )
Sets an option on the given cURL session handle. (具體請看 php 手冊) There:
CURLOPT_URL :The URL to fetch. You can also set this when initializing a session with curl_init().
CURLOPT_CONNECTTIMEOUT :The number of seconds to wait whilst trying to connect. Use 0 to wait indefinitely.(無限期等待 設(shè)置為 0)
CURLOPT_RETURNTRANSFER :TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
CURLOPT_FAILONERROR :TRUE to fail silently if the HTTP code returned is greater than or equal to 400. The default behavior is to return the page normally, ignoring the code.
CURLOPT_USERAGENT :The contents of the "User-Agent: " header to be used in a HTTP request.
7,curl_exec : Perform a cURL session, This function should be called after you initialize a cURL session and all the options for the session are set.
如果成功則返回 TRUE,失敗則返回 FALSE。 However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, FALSE on failure
8,curl_close -- Close a cURL session

下面是一些參考代碼:
php 采集程序 常用函數(shù)
php 采集獲取指定網(wǎng)址的內(nèi)容

php技術(shù)PHP 獲取遠(yuǎn)程文件內(nèi)容的函數(shù)代碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 迷你大冒险| 安装暖气片电话| 库存管理软件| 超越情感电视剧免费观看全集完整版| 秀人网周妍希| 无锡电视台| 团结力量歌词大全图片| jagger| 漫画启示作文五年级| 理发师的情人电影| 茶馆妈妈韩剧| 地球的宇宙环境教学反思| 猎魔人第三季 电视剧| 十大高蛋白食物蔬菜| 天地无伦| 林正英僵尸先生电影在线观看| 天下免费大全正版资料| 朱莉娅安| 胡金铨最好的十部电影| 凤凰卫视资讯台直播| 王子奇个人资料简介| 456电影在线| 林书宇| 连城诀1-40集全集免费| 变成黑皮辣妹然后和朋友做| 初夜在线观看| 妈妈的朋友欧美| 春香传在线观看| 内衣视频| 欧美视频亚洲视频| 电视剧火流星演员表| 妻子的电影| 搜狐首页网| 凤凰卫视节目表| alura jenson movies| 关于鲁迅的手抄报图片| 陆廷威| 妈妈的脊背简谱| 伤残等级1-10标准图| 电影不见不散| 基兰·拉奥|