Welcome Guest, Not a member yet? Register   Sign In
How can i trim text ?
#1

[eluser]margsot[/eluser]
I would like to trim text of one field called description to 100 characters.

I tried to use this php code in my view file but doesnt work.

Code:
$max_length = 100;

if (strlen($s) > $max_length)
{
    $offset = ($max_length - 3) - strlen($s);
    $s = substr($s, 0, strrpos($s, ' ', $offset)) . '...';
}
#2

[eluser]Syllean[/eluser]
The code works fine for me, are you sure that you passed $s into your view correctly?

You really shouldn't be dealing with this type of logic in your views anyway, it's better to process it in your controller.
#3

[eluser]anis2505[/eluser]
Take a look at the Text helper
http://ellislab.com/codeigniter/user-gui...elper.html
#4

[eluser]margsot[/eluser]
Thanks for your help. Now works fine




Theme © iAndrew 2016 - Forum software by © MyBB