Forums
This topic is locked
Trimming DB output
Posted 22 years ago
1
has voted
22 years ago 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 22 years ago
22 years ago 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>
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 22 years ago
22 years ago Jason Baxter replied:
Thanks Tony!
Your code was exactly what I need. Right on for posting your own answers.
Your code was exactly what I need. Right on for posting your own answers.