| |
 |
TG007.net Development Blog
|
 |
« Page Editing
I ran across this php script while searching for ways to repair my truncation script. I was having a bit of trouble with break tags being cut off and messing up the site validation. I used the idea from this script to fix that. Hope it helps others.
<?php
function truncate($text,$numb) {
$text = html_entity_decode($text, ENT_QUOTES);
if (strlen($text) > $numb) {
$text = substr($text, 0, $numb);
$text = substr($text,0,strrpos($text,” “));
//This strips the full stop:
if ((substr($text, -1)) == “.”) {
$text = substr($text,0,(strrpos($text,“.”)));
}
$etc = “…”;
$text = $text.$etc;
}
$text = htmlentities($text, ENT_QUOTES);
return $text;
}
//Call function
truncate($text, 75);
?>
Leave a Reply
|
|
|
|
July 25th, 2008 at 8:05 am
Thank You, ive been looking for code like this.