Skip to content

Instantly share code, notes, and snippets.

@WenLiangTseng
Created July 22, 2013 05:41
Show Gist options
  • Save WenLiangTseng/6051520 to your computer and use it in GitHub Desktop.
Save WenLiangTseng/6051520 to your computer and use it in GitHub Desktop.
使用CURL抓資料的PHP函數,可以給予URL資料,然後得到回傳的結果
<?php
$xml_file = file_get_contents(SITE_PATH . 'cms/data.php');
//CURL
function url_get_contents ($Url) {
if (!function_exists('curl_init')){
die('CURL 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