Limit a string to a certain character length grace
Login or Register to Bookmark this snippet
This function takes a long string of text and limits it to x many characters, stopping on a full world and appending '...' to the returned string.
<?php
function Truncate($string,$length) {
//truncates a string to a certain char length, stopping on a word.
if (strlen($string) >
$length) {
//limit! but also stop on a complete word..
$string =
substr($string,
0,
($length -3));
}
return $string;
}
?>
Added by JC on 12th November, 2007
There are no comments about this snippet.
You must be registered and logged in to post a comment.
Login here to post a comment