Finding a word with x characters before and after
Posted: Wed Feb 24, 2010 4:04 am
Hello everyone,
I've been trying to figure this out for a while though but no luck so far. First I'd like to find a word in a string, then I'd like to put x characters in front of this word in a new string, the word itself, and then y characters behind the word.
$str = "The quick brown fox jumped over the lazy dog.";
$search = "fox";
*some function with x=3 and y=6*
Should result in:
$newstring = "wn fox jumpe";
I think that this can be done with Regular Expressions?
Thanks for you help!
I've been trying to figure this out for a while though but no luck so far. First I'd like to find a word in a string, then I'd like to put x characters in front of this word in a new string, the word itself, and then y characters behind the word.
$str = "The quick brown fox jumped over the lazy dog.";
$search = "fox";
*some function with x=3 and y=6*
Should result in:
$newstring = "wn fox jumpe";
I think that this can be done with Regular Expressions?
Thanks for you help!