I have a list of keywords that I want to try and exact from a string that will contain html. I only want to get the exact word on it's own, i.e.
String = "This is a long string <a href="">cat</a> link. I love cats. I love cat.";
Word = "cat";
I only want to get the word "cat" when it's on it's own. I don't want it when it's apart of a link so or apart of another word cats. Just "cat". I will probably need to also check for punctuation like fullstops and commas.
My current code is:
preg_match_all('/\\b'.$word.'\\b/i', $string, $matches);
This sort of works- only if the word is within a link, it will match it also (which I don't want to happen).
Any ideas for this? I feel like it should be simple but I'm a bit stuck haha.
Thank you to anyone who helps