获取任意网站的标题 只是标题,以下代码获取不了网站内容,如果需要获取网站文章,需要根据不同网站的规则来写不同匹配代码。
if ($_GET['url']) {
$site='http://';
$url=trim($site.$_GET['url']);
$info=file_get_contents($url);
header('Content-type:text/json');
preg_match('|
(.*?)|i',$info,$m);if($url){
$result=array("code"=>"200","title"=>$m[1]);
echo json_encode($result,JSON_UNESCAPED_UNICODE);
}else{
$result=array("code"=>"201","meg"=>"ERREO");
echo json_encode($result,JSON_UNESCAPED_UNICODE);
}
}else{
$result=array("code"=>"201","meg"=>"ERREO");
echo json_encode($result,JSON_UNESCAPED_UNICODE);
}
?>