String search+select kind of function

i’m trying to write a function but with no luck. seems my brain capacity’s limited:)
the function will take two parameters: a term to search for, and a string to be searched. what i want the function to return is a new string containing the term (the parameter) along with a couple of words before and after it (as found in the search string). is anyone so kind as to help me with that?