PHP+regular splits alphanumeric and Chinese characters in a string

高洛峰
Release: 2023-03-05 13:22:01
Original
1620 people have browsed it

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

Result

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

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

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!