Heim >Backend-Entwicklung >PHP-Tutorial >php 判断字符串
php 判断字符串
<p class="sycode"> <? php function checkVS( $str ){ // 返回结果为1只有数字,2只有字符,3两者都有 $a = 0 ; $b = 0 ; for ( $i = 0 ; $i < strlen ( $str ); $i ++ ) { $v = ord ( substr ( $str , $i , 1 )); if ( $v >= 48 and $v <= 57 ) { $a = 1 ; } else { $b = 2 ; } } return $a + $b ; } echo checkVS( " sff " ) ?> </p>