function getHtml($url,$id=0){
$file_path = ATTACHEMENT_PATH.'caiji/';
if ($id) {
$file_path.=($id%10).'/';
}
if (!is_dir($file_path)) {
mkdir($file_path,0777,true);
}
$fname = md5(trim($url));
$file = $file_path.$fname.'.txt';
$string = file_get_contents($file);
if (!$string) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
$string = curl_exec($ch);
file_put_contents($file, $string);
}
return $string ;
}
转载于:https://www.cnblogs.com/yalibuxiao/p/4093197.html