Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created September 17, 2015 11:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/bb17fa953efe32774563 to your computer and use it in GitHub Desktop.
Save tommcfarlin/bb17fa953efe32774563 to your computer and use it in GitHub Desktop.
[PHP] A simple functions that can be used in place of file_get_contents that's powered by cURL.
<?php
/**
* Uses cURL rather than file_get_contents to make a request to the specified URL.
*
* @param string $url The URL to which we're making the request.
* @return string $output The result of the request.
*/
function url_get_contents ( $url ) {
if ( ! function_exists( 'curl_init' ) ) {
die( 'The cURL library is not installed.' );
}
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment