如何提取网站标题? [英] How do I extract title of a website?

查看:105
本文介绍了如何提取网站标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
解析HTML的最佳方法

Possible Duplicate:
Best methods to parse HTML

如何使用PHP提取网站标题?

How do I extract title of a website using PHP?

推荐答案

要使用HTML进行操作,您可以使用文档对象模型(这是推荐的方式).

To manupulate with HTML you can use Document Object Model (this is the recomended way).

如果您正在寻找一个肮脏的快速解决方案,那是相当简单的regexp:

If you are looking for a dirty fast solution, it's rather simple regexp:

$html = file_get_contents('http://example.com');
$matches = preg_match("/<title>([^<]*)<\/title>/im");
echo $matches[1];

这篇关于如何提取网站标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆