(Newbie) String within a string
| From: | jalist | Date: | Thu, 18 Jan 2001 13:48:57 +0000 |
| Subject: | (Newbie) String within a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-35345@lists.php.net to get a copy of this message | ||
I'm trying to grab a string from within a string based on a matching word or
phrase. Example...
$string = "This is a string I need to grab the middle out of"
$query_word = "need"
I need to get x amount of characters either side of $query_word, so the
result string would be like...
"string I need to grab the"
And I need the result string to be full words, not like..."ing I need to
grab th"
I've half managed to do it using strpos and substr but the code is really
messy and I'm getting half-formed words back. Anyone got any suggestion on
how to accomplish this?
Thanks very much in advance.
Steve