Home > Backend Development > PHP Tutorial > php 判断字符串

php 判断字符串

WBOY
Release: 2016-06-23 14:29:15
Original
1045 people have browsed it

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>
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template