This is the preferred way to grab external website content such as feeds using WordPress:
PHP Code:
function nb_fetch($url) {
/*
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_HEADER, 0); // Don't return http header
$feed = curl_exec($ch);
curl_close($ch);
*/
$response = wp_remote_request($url, array('headers' => array('user-agent' => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)')));
if ( is_wp_error( $response ) )
return '';
if ( 200 != $response['response']['code'] )
return '';
return $response['body'];
}
Bookmarks