下面是正则表达式
preg_match_all("/'<p'>(.*)".$_GET['searchString']."(.*)'<'/p'>/i", $contents, $matches, PREG_SET_ORDER);
将搜索我的字符串在<p> </p>
标签只在我的HTML页面。
谁能告诉我,如果我想在我的HTML页面内的所有HTML元素搜索我的字符串,我应该写什么正则表达式?
提前感谢。
下面的文章会让你明白我到底想做什么http://www.stratos.me/2009/07/search-feature-on-static-html-sites-the-smart-way/这样怎么样,这是你想要的吗?
<?php
$str="<p>test</p><P>test</p><b>test
</b>";
$key = "test";
preg_match_all("#<'s*([a-zA-Z]*)[^>]*>.*?{$key}.*?<'/'s*''1's*>#msi",$str,$match);
if(isset($match[0])) {
print_r($match[0]);
}else{
echo "No match";
}
#output
Array
(
[0] => <p>test</p>
[1] => <P>test</p>
[2] => <b>test
</b>
)
<?php
$str="<p>test</p><p>asasafs</p><p>xxxxr</p>";
preg_match_all("#<p>(.*?)<'/p>#",$str,$match);
if(isset($match[1])) {
print_r($match[1]);
}