sure, am actually doing this right now ;-)
It depends on how fancy you want to get...if you don't mind slicing off in
the middle of a word, you can just do this:
$preview_text = substr($text,0,200) . '. . .'; //gets the first 200
characters and adds an ellipsis afterwards

if you want to make sure you're stopping at a space try:
$preview_text = substr($text,0,strpos($text,' ',200)) . '. . .';//gets all
the text up to the first space that occurs after 200 chars

you want exactly fifty words, you could try something like this (untested)
preg_match("/^(\w+\s){50}/",$text,$match);
$preview_text = $match[0] . '. . .';

its late and i'm reaching the 10 hour coding mark, so there might be a
syntax error lurking in there, but those should at least get you
started.....

jack

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 07, 2001 3:19 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Newbie Question.. (MySQL/PHP)


Hey guys,

I have a mysql database of articles, and what i'd like to do is make 1 page
that shows a brief sneak peak of each article, so what I would do is, show
the first 50 or so words of each article and then add an elipses at the end.
I'm sure it can be done but I wouldn't have a clue where to start. Any
suggestions, or anyone ever done this?

Thanks,
Nate


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to