Home >Backend Development >PHP Tutorial >PHP+regular splits alphanumeric and Chinese characters in a string

PHP+regular splits alphanumeric and Chinese characters in a string

高洛峰
高洛峰Original
2017-02-06 16:48:261672browse

For example: $str="How does php split the 322 alphanumeric characters sf f45d and Chinese_ in the string?"; Split by numbers or letters.

$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);

Result

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

For more php+regular separation of alphanumeric and Chinese characters in a string, please pay attention to the PHP Chinese website!

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