Home >Backend Development >PHP Tutorial >Two methods for determining string length in PHP are very practical, strings are very practical_PHP tutorial

Two methods for determining string length in PHP are very practical, strings are very practical_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:08:05821browse

The two methods for PHP to determine the length of a string are very practical. Strings are very practical.

To determine the length of a string in a PHP program, you can use strlen.

Method 1:

$str = ‘aaaaaa';
if(strlen($str) > 6){
 echo "字符串大于6";
}

Method 2:

if(isset($str{6}){
}

The second method above 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 faster! So the second method can be used when determining whether a string is greater than or less than a number of characters.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1057471.htmlTechArticleThe two methods for PHP to determine the length of a string are very practical. Strings are very practical. To determine the length of a string in a PHP program, strlen can be used. Method 1: $str = ‘aaaaaa’;if(strlen($str) 6){ e...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn