响应式广告位

PHP获取网页标题和内容信息接口

PHP获取网页标题和内容信息接口
$url = filter(get(‘url’));
if (!$url) {
return json([‘code’ => -1, ‘msg’ => ‘链接不克不及为空!’]);
} else if (get_curl($url) === false) {
return json([‘code’ => -1, ‘msg’ => ‘提交的网址无法拜访!’]);
}
$data = get_curl($url);
//Title
preg_match(‘/([\\w\\W]*?)/si’, $data, $Title);
if (!empty($Title[1])) {
$title = $Title[1];
}
//Keywords
preg_match(‘/<META\\s+name=\"keywords\"\\s+content=\"([\\w\\W]*?)\"/si\', $data, $Keywords);
if (empty($Keywords[1])) {
preg_match(\"/<META\\s+name=\'keywords\'\\s+content=\'([\\w\\W]*?)\'/si\", $data, $Keywords);
}
if (empty($Keywords[1])) {
preg_match(\'/<META\\s+content=\"([\\w\\W]*?)\"\\s+name=\"keywords\"/si\', $data, $Keywords);
}
if (empty($Keywords[1])) {
preg_match(\'/<META\\s+http-equiv=\"keywords\"\\s+content=\"([\\w\\W]*?)\"/si\', $data, $Keywords);
}
if (!empty($Keywords[1])) {
$keywords = $Keywords[1];
}
//Description
preg_match(\'/<META\\s+name=\"description\"\\s+content=\"([\\w\\W]*?)\"/si\', $data, $Description);
if (empty($Description[1])) {
preg_match(\"/<META\\s+name=\'description\'\\s+content=\'([\\w\\W]*?)\'/si\", $data, $Description);
}
if (empty($Description[1])) {
preg_match(\'/’获取成功!’,’title’=>$title,’keywords’=>$keywords,’description’=>$description);
} else {
$result = array(‘code’=>-1,’msg’=>’站点信息获取失败!’);
}
if (json_encode($result) === false) {
return json([‘code’ => -1, ‘msg’ => ‘站点信息获取失败!’]);
} else {
return json($result);
}

© 版权声明
THE END
喜欢就支持一下吧
点赞580赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容