Re: (Newbie) String within a string
| From: | Angus Mann | Date: | Fri, 19 Jan 2001 23:42:28 +0000 |
| Subject: | Re: (Newbie) String within a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-35755@lists.php.net to get a copy of this message | ||
At 13:48 18/01/01 +0000, jalist wrote:
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.I'd suggest using regular expressions (ereg, or preg_match). It's a little too early in the morning on a weekend for me to come up with the best example of what would work, sorry :) Angus.