Skip to content

Instantly share code, notes, and snippets.

@trvswgnr
Last active August 31, 2020 15:59
Show Gist options
  • Save trvswgnr/130954e76f2f5e553df59207ddbc4589 to your computer and use it in GitHub Desktop.
Save trvswgnr/130954e76f2f5e553df59207ddbc4589 to your computer and use it in GitHub Desktop.
PHP - Get contents of remote url using cURL
<?php
/**
* Get contents of remote url
*
* @see https://knowledgecornor.blogspot.com/2013/10/filegetcontents-vs-curl.html
* @author Travis Aaron Wagner
*
* @param string $url URL to get.
* @return string $output Remote url contents.
*/
function curl_get_contents( $url ) {
$ch = curl_init();
curl_setopt_array(
$ch,
array(
CURLOPT_URL => $url,
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1,
)
);
$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