I have an HTML document as a string
I want to search for a keyword in this document and figure out where did it appear in the document
I mean in which tag did it appear
did it appear in H1,H2 or TITLE tag
lets say my document is
$string = "<html>
<head>
<title>bar , this is an example</title>
</head>
<body>
<h1>latest news</h1>
foo <strong>bar</strong>
</body>
</html>";
$arr = find_term("bar",$string);
print_r($arr);
I expect the result to be like this
[0]=> title
[1]=> strong
because "bar" appeared one time in TITLE tag and one time in the STRONG tag
I knew it is a complicated question, that is why I am asking if someone knows the answer :)
thanks
what I have so far is
function find_term($term,$string){
$arr = explode($term, $string);
return $arr;
}
$arr = find_term("bar",$string);
print_r($arr);
now we have an array which has the value
Array
(
[0] => <html>
<head>
<title>
[1] => , this is an example</title>
</head>
<body>
<h1>latest news</h1>
foo <strong>
[2] => </strong>
</body>
</html>
)
you can see that the last tag of every element of the array is the tag which contains "bar" but the question now is how to know the last tag appeard in every element?
Thanks