一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

PHP 獲取遠程文件內容的函數代碼

如下函數:
復制代碼 代碼如下:
<?
/**
獲取遠程文件內容
@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;
}
?>

相關解釋:
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(配置文件中的內容)
3,fopen( "rb"): 在操作二進制文件時如果沒有指定 'b' 標記,可能會碰到一些奇怪的問題,包括壞掉的圖片文件以及關于 /r/n 字符的奇怪問題。
注意: 為移植性考慮,強烈建議在用 fopen() 打開文件時總是使用 'b' 標記。
注意: 再一次,為移植性考慮,強烈建議你重寫那些依賴于 't' 模式的代碼使其使用正確的行結束符并改成 '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(提供設置)
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.(無限期等待 設置為 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 采集程序 常用函數
php 采集獲取指定網址的內容

php技術PHP 獲取遠程文件內容的函數代碼,轉載需保留來源!

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

主站蜘蛛池模板: 成人福利免费在线观看 | 碰碰人人| 国产亚洲精品国产福利在线观看 | 日本污视频网站 | 中国成人在线视频 | 国产在线更新 | 色在线网站 | 9久热这里只有精品免费 | 亚洲综合色一区二区三区小说 | 精品香蕉一区二区三区 | 日本波多野结衣在线 | 午夜免费视频网站 | 久久中文字幕综合不卡一二区 | 婷婷激情综合 | 愉拍自拍一区首页 | 国产白白视频在线观看2 | 亚欧美视频 | 精品国产一区二区三区免费 | 国产91在线精品福利 | 青青在线精品 | 91精品国产高清久久久久久91 | 国产在线一区二区三区在线 | 首页 动漫 亚洲 欧美 日韩 | 91精品一区二区三区在线观看 | 人人九九精 | 草久久久 | 欧美日韩亚洲国产精品一区二区 | 亚洲国产lv | 三级小说第一页 | 网站色哟哟 | 国内免费高清视频在线观看 | 91麻豆国产自产 | 色欧洲| 国产欧美日韩免费一区二区 | 国产视频一区二区在线观看 | 久久国产乱子免费精品 | 视频二区在线观看 | 97一区二区三区 | 亚洲热在线观看 | 在线视频一区二区三区三区不卡 | 美女网站色黄 |