This article mainly introduces the judgment of string length in PHP program. Interested friends can refer to it. I hope it will be helpful to everyone.
Method one:
$str = ‘aaaaaa'; if(strlen($str) > 6){ echo "字符串大于6"; }
Method two:
if(isset($str{6}){ }
The second method is more efficient.
In PHP, all variables are saved using a structure -zval. Although strlen directly obtains the len, there is still a function call, and isset is a syntax structure of PHP, so it is more quick! So the second method can be used when determining whether a string is greater than or less than a number of characters.
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
php method to create a multi-level directory complete encapsulation class
PHP infinite loop acquisition MySQL data
php determines whether the required parameters in the function exist
The above is the detailed content of String length judgment in php program. For more information, please follow other related articles on the PHP Chinese website!