【发布时间】:2015-03-27 08:29:05
【问题描述】:
我有这个 SEO 脚本,我在 $row['content'] 中查找 $row_meta['keyword'] 这是我的搜索焦点关键字.
我想检查是否有 h1、h2、h3 或 h4 标签包含我的关键字。例如,如果我的 $row_meta['keyword'] = "test"; 这个文本应该是匹配的:
This is my text
<h2>We just want to test</h2>
but this text containing test is not a match, only between h tags.
有人能帮帮我吗?
我有类似的东西,它正在测试我是否有任何包含带有我的关键字的 alt 标签的 img 标签,这是我的代码:
$dom = new DOMDocument();
$dom->loadHTML($row['content']);
foreach ($dom->getElementsByTagName('img') as $img) {
$alt = $img->getAttribute('alt');
if (preg_match("/\b".$row_meta['keyword']."\b/", $alt)) {
$counter++;
}
}
【问题讨论】:
标签: php pattern-matching preg-match match h2