以下是获取网站标题的PHP代码:

$url = "https://www.example.com";
$html = file_get_contents($url);
preg_match("/<title>(.*)<\/title>/i", $html, $matches);
$title = $matches[1];
echo $title;

解释:

  1. 定义一个变量 $url 存储要获取标题的网站的URL。
  2. 使用 file_get_contents() 函数获取网站的HTML代码。
  3. 使用正则表达式 /<title>(.*)<\/title>/i 匹配 HTML 中的标题标签,并将标题存储在 $matches 数组中。
  4. $matches 数组中获取标题,并将其存储在 $title 变量中。
  5. 使用 echo 函数输出标题。
网站域名获取标题PHP代码

原文地址: https://www.cveoy.top/t/topic/bJOj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录