有些主機服務商把php的allow_url_fopen選項是關閉了
下面是file_get_contents和curl兩個函數同樣功能的不同寫法
file_get_contents函數的使用示例:
< ?php
$file_contents = file_get_contents(
echo $file_contents;
?>
換成curl函數的使用示例:
< ?php
$ch = curl_init();
$timeout =
curl_setopt ($ch
curl_setopt ($ch
curl_setopt ($ch
$file_contents = curl_exec($ch);
curl_close($ch);
echo $file_contents;
?>
利用function_exists函數來判斷php是否支持一個函數可以輕松寫出下面函數
< ?php
function vita_get_url_content($url) {
if(function_exists(
$file_contents = file_get_contents($url);
} else {
$ch = curl_init();
$timeout =
curl_setopt ($ch
curl_setopt ($ch
curl_setopt ($ch
$file_contents = curl_exec($ch);
curl_close($ch);
}
return $file_contents;
}
?>
其實上面的這個函數還有待商榷
From:http://tw.wingwit.com/Article/program/PHP/201311/21042.html