Re: Get just first 200 characters of field?
| From: | Daniel Convissor | Date: | Wed, 18 Oct 2000 16:41:18 +0000 |
| Subject: | Re: Get just first 200 characters of field? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-20936@lists.php.net to get a copy of this message | ||
Hey James:
> Im working on my own news managment system for my web site, and I would like
> to be able to post on the main page the article header, and just the first
> 200 or so characters of the actual content of the article.
>
> How can this be done? Using PHP3 and MySQL? Is there a specific PHP or
> MySQL function that would accomplish this?
I'd use MySQL's left() function inside the query, like:
SELECT Title, left(Article,200) as Summary FROM Articles
This has the benefit of being fast and reducing the memory needed by only
pulling out 200 characters rather than pulling out the whole thing and then
stripping it down.
Some folks suggested finding the end of a sentence. If you want to go that
route, consider MySQL's SUBSTRING_INDEX() function.
I'd probably go with the left() procedure. Simpler, faster.
Enjoy,
--Dan
--
PHP scripts that make your job easier
http://www.analysisandsolutions.com/code/
SQL Solution | Layout Solution | Form Solution
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
4015 7 Ave, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409