Last active
August 31, 2020 15:59
-
-
Save trvswgnr/130954e76f2f5e553df59207ddbc4589 to your computer and use it in GitHub Desktop.
PHP - Get contents of remote url using cURL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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