Danny159
09-09-2009, 04:33 AM
Hey,
I have a database that runs the news for a website, this includes HTML such as <b>, <i>, <u>
However I need to make the text shorter to 255 letters and add ... but take of ending of words.
But I cant get my script to do it!
Here is that I have....
$desc = $row["post_content"];
$desc = trim(substr($desc, 0, 256));
$len = strlen($desc) -1;
$x = strpos($desc, '<');
if($x !== false && $x < $len) $len = $x;
if($desc[$len] != ".")
{
while($len > 20 && ord($desc[$len]) != 32) $len--;
}
$desc = trim(substr($desc, 0, $len)) . "...";
echo "$desc";
Please help asap
Dan
I have a database that runs the news for a website, this includes HTML such as <b>, <i>, <u>
However I need to make the text shorter to 255 letters and add ... but take of ending of words.
But I cant get my script to do it!
Here is that I have....
$desc = $row["post_content"];
$desc = trim(substr($desc, 0, 256));
$len = strlen($desc) -1;
$x = strpos($desc, '<');
if($x !== false && $x < $len) $len = $x;
if($desc[$len] != ".")
{
while($len > 20 && ord($desc[$len]) != 32) $len--;
}
$desc = trim(substr($desc, 0, $len)) . "...";
echo "$desc";
Please help asap
Dan
