Hi, I am trying to create a regex that will do the following
take 5 words before the search phrase (or x, if there are only x words) and 5 words after the search phrase (or x, if there are only x words) from a block of text (when I say words I mean words or numbers, which are in the block of text)
eg,
Welcome to stack overflow! Visit your user page to provide your name and email address.
if you were to look for a βvisit,β he will return: Welcome to the stack overflow! Visit your user page to install
the idea is to use preg_match_all in php to give me a bunch of search results showing where the search phrase appears in the text for each occurrence of the search phrase.
Thanks in advance: D
on an extra note, there may be a better way to get to my result, if you feel that there is, please feel free to throw it in the pool, as I'm not sure if this is the best only first way I thought of doing what I need: D
source share