Below is my regular expression
preg_match_all("/\<p\>(.*)".$_GET['searchString']."(.*)\<\/p\>/i", $contents, $matches, PREG_SET_ORDER);
which will search my string within <p> </p>
Tags only inside my HTML page.
Can anyone tell me that if i want to search my string in all the HTML element inside my HTML page , what regular expression i should write ?
Thanks in advance.
Below artical will make you understand that what exactly i want to do http://www.stratos.me/2009/07/search-feature-on-static-html-sites-the-smart-way/
<?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]);
}
How about this way, is this your want?
<?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>
)