allow_url_fopen が off になってたときの対処法

海外の無料ホスティングサーバにて、PHPをアップしたところ

Warning: fopen(): URL file-access is disabled in the server configuration in ・・・

というメッセージが表示されて、外部サーバのファイルやRSSを読み込めない状態になっていました。
原因としては、PHP Core の [allow_url_fopen]がoffになってる事が原因のようです。

これの対処方法として、いろいろ検索していたら、curl を使った解決法を見つけました。
以下のコードで、解決されました。

 /*
 * @return string
 * @param string $url
 * @desc Return string content from a remote file
 * @author Luiz Miguel Axcar (lmaxcar@yahoo.com.br)
 */

function get_content($url)
{
$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);

ob_start();

curl_exec ($ch);
curl_close ($ch);
$string = ob_get_contents();

ob_end_clean();

return $string;
}

#usage:
$content = get_content ("http://www.php.net");
var_dump ($content);

ネタの出所:
PHP Manual : fopen
「Luiz Miguel Axcar (lmaxcar at yahoo dot com dot br)」さんの投稿記事より