RE: [PHP] Newbie Question.. (MySQL/PHP)

From: Date: Fri, 07 Sep 2001 07:25:03 +0000
Subject: RE: [PHP] Newbie Question.. (MySQL/PHP)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-66345@lists.php.net to get a copy of this message
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: nate@1feehosting.com [mailto:nate@1feehosting.com] Sent: Friday, September 07, 2001 3:19 AM To: php-general@lists.php.net 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

« previous php.general (#66345) next »