How to see if a string is too long.

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
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

How to see if a string is too long.

Post by gotDNS »

Ok, now that i can get the length of a string: how would i dosomething like:

if the length of the string is over 240 characters: echo "too long.";

That as an example...but how might i do that?

thanks
Elfstone
Forum Newbie
Posts: 21
Joined: Tue Jun 11, 2002 2:25 am
Location: NJ, USA

Post by Elfstone »

Code: Select all

if (strlen($yourstring) > "240") {
echo "too long";
}
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

Post by gotDNS »

Thanks, dude! *progresses once again on tedious parts of a site.*

later on, -Brian
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

or if you want to cut it off,

if(strlen($str) > 240){
$str = substr($str, 0, 237)."...";
}
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

Post by gotDNS »

ooo, thankee very much! I can use such information in 2 places!

*improves site layout by cutting back on the length of an entry...*

Thanks!

later on, -Brian
Post Reply