最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2010年03月24日 19:38:03   作者:  
PHP 獲取遠(yuǎn)程文件內(nèi)容的代碼,后面有一些注釋可以參考下,其實大家可以參考腳本之家發(fā)布的一些采集程序代碼。
如下函數(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"): 在操作二進制文件時如果沒有指定 '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)容

相關(guān)文章

  • php+curl 發(fā)送圖片處理代碼分享

    php+curl 發(fā)送圖片處理代碼分享

    這篇文章主要介紹了php+curl 發(fā)送圖片處理代碼分享的方法的相關(guān)資料,需要的朋友可以參考下
    2015-07-07
  • Function eregi is deprecated (解決方法)

    Function eregi is deprecated (解決方法)

    本篇文章是對Function eregi() is deprecated錯誤的解決方法進行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • PHP CLI模式下的多進程應(yīng)用分析

    PHP CLI模式下的多進程應(yīng)用分析

    PHP在很多時候不適合做常駐的SHELL進程, 他沒有專門的gc例程, 也沒有有效的內(nèi)存管理途徑. 所以如果用PHP做常駐SHELL, 你會經(jīng)常被內(nèi)存耗盡導(dǎo)致abort而unhappy
    2013-06-06
  • 控制PHP的輸出:緩存并壓縮動態(tài)頁面

    控制PHP的輸出:緩存并壓縮動態(tài)頁面

    PHP4中最令人滿意的事是——你可以讓PHP緩存所有由腳本生成的輸出,在你決定把它們送出之前,瀏覽器方是不會收到任何內(nèi)容的
    2013-06-06
  • php cli模式下獲取參數(shù)的方法

    php cli模式下獲取參數(shù)的方法

    本篇文章主要介紹了php cli模式下獲取參數(shù)的方法,具有很好的參考價值。下面跟著小編一起來看下吧
    2017-05-05
  • PHP緩存系統(tǒng)APCu擴展的使用

    PHP緩存系統(tǒng)APCu擴展的使用

    這篇文章主要介紹了PHP緩存系統(tǒng)APCu擴展的使用,幫助大家更好的理解和學(xué)習(xí)使用php,感興趣的朋友可以了解下
    2021-04-04
  • 淺析PHP中Collection 類的設(shè)計

    淺析PHP中Collection 類的設(shè)計

    本篇文章是對PHP中Collection 類進行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • PHP+RabbitMQ實現(xiàn)消息隊列的完整代碼

    PHP+RabbitMQ實現(xiàn)消息隊列的完整代碼

    這篇文章主要給大家介紹了關(guān)于利用PHP+RabbitMQ實現(xiàn)消息隊列的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用PHP具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • PHP學(xué)習(xí)之?dāng)?shù)組的定義和填充

    PHP學(xué)習(xí)之?dāng)?shù)組的定義和填充

    先了解一下數(shù)組,數(shù)組就是把一組數(shù)據(jù)按順序放在一起。PHP的數(shù)組和其它的語言數(shù)組有一點點不同:第一,保存的數(shù)據(jù)是可以是任何類型的;第二,數(shù)組的索引可以是數(shù)字,也可以是字符串。
    2011-04-04
  • php+js實現(xiàn)的拖動滑塊驗證碼驗證表單操作示例【附源碼下載】

    php+js實現(xiàn)的拖動滑塊驗證碼驗證表單操作示例【附源碼下載】

    這篇文章主要介紹了php+js實現(xiàn)的拖動滑塊驗證碼驗證表單操作,結(jié)合實例形式分析了php+js拖動滑塊驗證碼驗證表單操作基本功能實現(xiàn)與使用相關(guān)操作技巧,需要的朋友可以參考下
    2020-05-05

最新評論

娄底市| 宁河县| 宁蒗| 文化| 渑池县| 南川市| 济源市| 聂拉木县| 三都| 滁州市| 来凤县| 荥经县| 兰溪市| 景东| 黄龙县| 临城县| 大冶市| 尚义县| 信阳市| 海林市| 特克斯县| 鹤山市| 辽阳县| 公安县| 如皋市| 潮州市| 霍林郭勒市| 南乐县| 南昌县| 道真| 平泉县| 霍林郭勒市| 保德县| 方山县| 启东市| 通化市| 望都县| 千阳县| 北碚区| 青浦区| 营口市|