Home >Backend Development >PHP Tutorial > php怎么将字符串中的字母数字和中文分割

php怎么将字符串中的字母数字和中文分割

WBOY
WBOYOriginal
2016-06-13 13:40:531076browse

php如何将字符串中的字母数字和中文分割?
如:$str="php如何将字 符串中322的字母数字sf f45d和中文_分割?";按数字或字母分割。得到数组:

$new = array();

$new[0]="php";
$new[1]="如何将字 符串中";
$new[2]="322";
$new[3]="的字母数字";
$new[4]="sf";
$new[5]=" ";
$new[6]="f45d";
$new[7]="和中文_分割?";

------解决方案--------------------
看一下手册就知道了

PHP code
$str = "php如何将字 符串中322的字母数字Asf f45d和中文_分割?";
$arr = preg_split("/([a-zA-Z0-9]+)/", $str, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);  
print_r($arr); <div class="clear">
                 
              
              
        
            </div>
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