How to check if variable is null or empty in strlen with PHP

3 Answers

0 votes
$string = "php";

$result = strlen($string ? $string : "") > 2 ? "yes" : "no";

echo $result;




/*
run:

yes

*/

 



answered May 25, 2022 by avibootz
0 votes
$string = "";

$result = strlen($string ? $string : "") > 2 ? "yes" : "no";

echo $result;




/*
run:

no

*/

 



answered May 25, 2022 by avibootz
0 votes
$string = null;

$result = strlen($string ? $string : "") > 2 ? "yes" : "no";

echo $result;




/*
run:

no

*/

 



answered May 25, 2022 by avibootz
...