Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php check if variable length equals a value

Tags:

php

Need to check if $message length is 7 characters or less, if so, do action A, if not, do action B. Is this correct syntax? I think im doing something wrong?

<?php

if (strlen($message) <= 7) {
    echo $actiona;
} else {
    echo $actionb;
}

?>
like image 553
mrpatg Avatar asked Jul 17 '09 06:07

mrpatg


1 Answers

It's fine. For example, let's run the following:

<?php

$message = "Hello there!";

if (strlen($message) <= 7){
    echo "It is less than or equal to 7 characters.";
} 
else 
{
    echo "It is greater than 7 characters.";
}
?>

It will print: "It is greater than 7 characters."

like image 56
Evan Fosmark Avatar answered Oct 29 '22 11:10

Evan Fosmark