PROBLEM:
I want to produce short "snippets" for search result pages. The search results are already partially processed (search terms get wrapped in [strong] tags), but I keep hitting dead-ends with this step. Now, I've tried a wide number of approaches, spent an embarasing amount of time and arrived at no viable solution. Learning regular expressions would probably have been less painfull, but there you have it.
This should produce what you want (or darn close):
preg_match_all('/(\S+\s*){0,5}<strong class="term[1-3]">([^<]+)<\/strong>(\s*\S+){0,5}/',$str,$matches);
echo 'Summary: ' . implode(' ... ',$matches[0]);
where $str is your text.
-- ---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals - www.phparch.com
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php