Forums

PHP

This topic is locked

Trimming DB output

Posted 30 Dec 2002 18:46:11
1
has voted
30 Dec 2002 18:46:11 Anthony Covert posted:
I am extremely new to PHP and I was wondering how i trim output from the DB to show less characters.

For example: In a news article clip on the sites homepage I would like to show exactly that, a clip of the main storys content (maybe 250 characters or words) and then provide a link to the full article body.

Any ideas or tuts out there?

Thanks in advance,
Tony

Replies

Replied 02 Jan 2003 18:29:34
02 Jan 2003 18:29:34 Anthony Covert replied:
In case anyone else is trying to solve this case I found an answer in the form of a function here: www.php.net/manual/en/function.substr.php

Here is the post -

How to make a nice trim of text without break words in the middle :

$maxTextLenght=125;
$aspace=" ";
if(strlen($text) > $maxTextLenght ) {
$text = substr(trim($text),0,$maxTextLenght);
$text = substr($text,0,strlen($text)-strpos(strrev($text),$aspace));
$text = $text.'...';
}

Hope this helps future newbies!
<img src=../images/dmxzone/forum/icon_smile_big.gif border=0 align=middle>

Tony<i></i><i></i><i></i>
Replied 16 Jan 2003 22:09:03
16 Jan 2003 22:09:03 Jason Baxter replied:
Thanks Tony!

Your code was exactly what I need. Right on for posting your own answers.

Reply to this topic