mrpatg mrpatg - 1 year ago 58
PHP Question

php check if variable length equals a value

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?

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

Answer Source

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."

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download