由于某種原因把php的allow_url_fopen選項是關閉了,就是沒法直接使用file_get_contents來獲取遠程web頁面的內容,那就是可以使用另外一個函數curl.
無限file_get_contents獲取遠程網頁內容函數,代碼如下:
- function vita_get_url_content($url) {
- if(function_exists('file_get_contents')) {
- $file_contents = file_get_contents($url);
- } else {//開源代碼Vevb.com
- $ch = curl_init();
- $timeout = 5;
- curl_setopt ($ch, curlopt_url, $url);
- curl_setopt ($ch, curlopt_returntransfer, 1);
- curl_setopt ($ch, curlopt_connecttimeout, $timeout);
- $file_contents = curl_exec($ch);
- curl_close($ch);
- }
- return $file_contents;
- }
由于某種原因把php的allow_url_fopen選項是關閉了,就是沒法直接使用file_get_contents來獲取遠程web頁面的內容,那就是可以使用另外一個函數curl.
新聞熱點
疑難解答