tags:

views:

244

answers:

5
if (strlen($comment > 2)) {

Ok, so I only want to exec this if $comment consist of more than 2 characters
I believe strlen should do this, but it doesn't. Am I using it wrong?

+7  A: 

Your closing parenthesis is in the wrong place:

if (strlen($comment) > 2) {

}
Jonathan Sampson
+1  A: 

It should be:

if (strlen( $comment ) > 2 ) {
anon
+2  A: 

I don't know php. But perhaps you should try

if (strlen($comment) > 2) {
Danra
A: 

Haha what a failure i am. thanks everybody im gonna mark Danras answer since he/she was first

Actually, Jonathan was first - not that it matters.
anon
Actually, I was first - then Neil, THEN Danra.
Jonathan Sampson
Well, Neil, it matters a little bit ;) Hehe.
Jonathan Sampson
oh youre right i thought the other way around, haha
Thanks, Ralf! Appreciate the points.
Jonathan Sampson
I'm upvoting both for coming in with the same answer quickly.
Jonathan Sampson
Oh come on, I've only got 69 points...I couldn't even comment a few minutes ago! :-)
Danra
A: 

should be:

if ( strlen($comment) > 2 ) {

You might also want to trim() the comment as well to make sure it's more than two non-whitespace characters:

if ( strlen(trim($comment)) > 2 ) {
Eric Petroelje