Limit $variable value to 20 characters

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DynamiteHost
Forum Commoner
Posts: 69
Joined: Sat Aug 10, 2002 5:33 pm

Limit $variable value to 20 characters

Post by DynamiteHost »

How would I go about limiting the output value to 20 characters?

So when its printed, it displays only 20 chars.

Thanks :)
Last edited by DynamiteHost on Sun Aug 11, 2002 5:16 am, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

print( (strlen($var)>20) ? substr($var, 0, 20) : $var );
Post Reply