I want to highlight keywords in a sentence by PHP.
This is my code:
preg_replace("/\p{L}*?".preg_quote($string)."\p{L}*/ui", "<b>$0</b>", $info->plaintext)
Now I’d like to know how to highlight next and previous words.
Example:
The good guys don’t always have to be warm and cuddly
If the keyword is Cuddly, it should result in warm and cuddly being highlighted. So the script should bypass and,or and highlight warm with it.
Another example and simple one (good is the keyword):
Sentence:
This school is a very good one.
The result:
This school is a very good one.
Something along these lines:
Just apply the same logic to the end, if you need “and *” after the word, too. Here’s a demo.