What I need to do is loop through the string and find occurrences of another string, then backtrack and save text before, inside and after the occrrence.
Given the string:
$haystack = "the quick brown fox jumped over the fence. the quick brown fox jumped over the hill. the quick brown fox jumped over the hole.";And I wanted to find the entire sentence that contained the word "hill".
$needle = "hill";How would I get the output:
$pincushion = "the quick brown fox jumped over the hill.";And assume that the first portion of the sentence is not always the same. Some days it will be:
$pincushion = "the slow red hen jumped over the hill.";I also need to preserve the original string, as there will be multiple searches made.
I do know a bit about PHP, but I'm fairly new to the finer points of string functions. Any help would be appreciated.