strange problem here that I’ve been pondering. I have a string that contains HTML, possibly with hyperlinks in it. Consider the text below:
Hello this is my EXAMPLE string of html here's a <tag> and here's another </tag>. Blah blah I'm going to hyperlink some stuff with <a href="http://www.example.com/> anchor text </a> and then finish my sentence.
As you can see above, the phrase anchor text is the anchor text for a hyperlink to example.com.
I want to be able to search for a substring like anchor or example and determine whether or not each occurrence is part of a hyperlink, whether it be anchor text, the url, or the a tag.
Preferably, there would be an array returned with a true/false for each occurrence of the search term. Case-insensitive search would be good, and it would be nice if it returned the matching occurrence, so we’d know the case and such. An ideal response for the above example would be something like this:
$array[0][0] = "EXAMPLE"
$array[0][1] = false
$array[1][0] = "example"
$array[1][1] = true
The index of each occurrence might also be useful information to return. Thanks!
You need to check all three cases, I think.
covers the first case,
would cover the second and third cases.
Or maybe you’d better check with a more tolerant regexp,
and then verify with a HTML parser if the found text is indeed a valid A tag. The first test would ensure you that your text is in the captured snippet, and the second that the snippet is indeed a hyperlink.