当前位置:首页 >> 线报活动 >> PHP获取网页标题和内容信息接口

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

admin 线报活动 5
$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('/<TITLE>([\w\W]*?)<\/TITLE>/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('/<META\s+content="([\w\W]*?)"\s+name="description"/si', $data, $Description);
}
if (empty($Description[1])) {
    preg_match('/<META\s+http-equiv="description"\s+content="([\w\W]*?)"/si', $data, $Description);
}
if (!empty($Description[1])) {
    $description = $Description[1];
}
if ($Title[1] !== "") {
    dataLog('URL['.$url.发布单页信息获取成功!','1','1');
    $result = array('code'=>0,'msg'=>'获取成功!','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);
}
复制代码
首码项目线报网
协助本站SEO优化一下,谢谢!
关键词不能为空
同类推荐

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。
«    2025年4月    »
123456
78910111213
14151617181920
21222324252627
282930
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
搜索
最新留言
文章归档
网站收藏
友情链接