I am creating a search for a keyword in a string of text. For example: Let's say I want to find the word 'Happy' and how many times it shows up in a book. Then I want to display 100 characters before and after the word, and do this for every word 'Happy' it finds.
I was able to find code to do it ONCE but how can I do this for all the occurrences of the keyword, in this case the word 'Happy'?
Here is the working code that finds one occurrence and displays characters before and after.
$text= $Content;
$find = 'Happy';
$result = strpos($text, $find);
echo substr($text,($result-100>0)?($result-100):0,100)." ".$find." "
.substr($text,$result+strlen($find),100);
How I can do this in a loop and find all the occurrences of a keyword?