I want to be able to display a string of characters up to 10 characters. If the string goes over 10 characters, I\'d like to append \'...\' to the end.
For example, if
Without using any serverside
script or javascript
you can not do this.
Use below function.
function LimitCharacter($data,$limit = 20)
{
if (strlen($data) > $limit)
{
$data = substr($data, 0, strrpos(substr($data, 0, $limit), ' ')) . '...';
return $data;
}
else
{
return $data;
}
}
call it as LimitCharacter($yourString,5);
Javascript
var str = 'Some very long string';
if(str.length > 10) str = str.substring(0,10)+"...";
CSS
.limtiCharClass {
-o-text-overflow: ellipsis; /* Opera */
text-overflow: ellipsis; /* IE, Safari (WebKit) */
overflow:hidden; /* don't show excess chars */
white-space:nowrap; /* force single line */
width: 300px; /* fixed width */
}