wangy 发表于 2021-6-20 21:46:23

【PHP教程】获取目标网站标题

<?php
if ($_GET['url']) {
    $site='http://';
    $url=trim($site.$_GET['url']);
    $info=file_get_contents($url);
    header('Content-type:text/json');
    preg_match('|<title>(.*?)<\/title>|i',$info,$m);
    if($url){
      $result=array("code"=>"200","title"=>$m);
      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);
}
//使用方法:http://xxx.com/xxx.php?url=www.baidu.com
//欢迎访问:http://ilovem.cn 网站
?>
页: [1]
查看完整版本: 【PHP教程】获取目标网站标题