Retrieving x number of words from text field?
| From: | Murray Wells | Date: | Sun, 15 Jun 2003 11:40:24 +0000 |
| Subject: | Retrieving x number of words from text field? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-151562@lists.php.net to get a copy of this message | ||
Hello All,
I have a page that displays a summary of records available for view.
As part of that summary I'd like to be able to retrieve and display x
number of words (perhaps 15 or 20?) excluding punctuation (as in, I want
the punctuation to be present, but not to count towards the word total,
so "this ... that" would be 2 words, not 3) as an intro to the text in
that record.
The tricky thing is (at least, it seems tricky to me) is that I would
like all content within an "<a href="" class=""></a>" tag
to be treated
as a word. So, if I set the retrieval number to be 10 words, the
following would hopefully be retrieved:
"one two three <a href="http://www.awebsite.com"
class="link">some text
describing the site</a> five six seven eight nine ten"
I think I could probably achieve this using a fairly brutish technique
of working through the string of the text for each record character by
character and keeping a word count, but I wondered if anyone could think
of a more graceful / efficient approach?
Any help very appreciated!
Much warmth,
Murray
http://www.planetthoughtful.org
Building a thoughtful planet,
one snide comment at a time...