This topic is locked
[SOLVED]

 Limit number of characters in Custom view

9/5/2013 7:32:58 AM
PHPRunner General questions
S
scoobysteve author

Can someone please tell me how to limit the amount of text shown in field I have a description box that I want to show a snippet of its contents on the list page, I am guessing its a custom view but i am not sure of the code.
Thanks

C
cgphp 9/5/2013
S
scoobysteve author 9/5/2013



The easy way http://php.net/manual/en/function.substr.php


This does not seem easy. I found this searching around it works but is there a way to add .....More at the bottom of the limit.

So it looks better rather than chopping of a word half way through, or could this be changed to count words not characters
//Truncate field text

$lenght_limit = 200; //limit to this number of characters

$actual_length = strlen($value); //count characters in the $value

$mytext = $value;

$mytext = substr($mytext,0,$lenght_limit ); //picks up characters from left to right starting at position zero all the way to 25
//Truncate if exceeds $chars value!

if($actual_length <= $length_limit){

$value = $mytext;

} else {

$mttext = $mytext."...";

$value = $mytext;

}

C
cgphp 9/6/2013

explode (http://php.net/manual/en/function.explode.php) can help you to limit by words.