PHP获取网页标题、描述和关键词的方法

编程开发   © 文章版权由 admin 解释,禁止匿名转载

#楼主# 2023-4-2

这篇文章主要介绍了怎样通过PHP获取网页标题、描述和关键词的方法
分别使用了
curl_init()
curl_setopt()curl_exec()
curl_close()
preg_match()
函数来实现,需要的朋友可以参考下

注:如果报错请 1. 找到c:\php\php.ini文件 2. 搜索到extension=php_curl.dll 后把前面的分号去掉

获取方法1:

$ch = curl_init("http://www");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);

$title = preg_match('!(.*?)!i', $result, $matches) ? $matches[1] : 'No title found';
$description = preg_match('!!i', $result, $matches) ? $matches[1] : 'No meta description found';
$keywords = preg_match('!!i', $result, $matches) ? $matches[1] : 'No meta keywords found';

echo $title . '
';
echo $description . '
';
echo $keywords . '
';
//输出结果为:
//psd
//第一素材
//素材
?>

成为第一个回答人

评论

登录后才可发表内容
  • 主题

    30

  • 帖子

    3752

  • 关注者

    0

Copyright © 2019 凯特网.   Powered by HYBBS 2.3.4  

Runtime:0.2849s Mem:2459Kb