如:$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]="和中文_分割?";
$new[1]="如何将字 符串中";
$new[2]="322";
$new[3]="的字母数字";
$new[4]="sf";
$new[5]=" ";
$new[6]="f45d";
$new[7]="和中文_分割?";
===================================================================
$str = "php如何将字 符串中322的字母数字Asf f45d和中文_分割?";
$arr = preg_split("/(?=[a-zA-Z0-9])/", $str);
print_r($arr); 结果:
Array (
[0] =>
[1] => p
[2] => h
[3] => p如何将字 符串中
[4] => 3
[5] => 2
[6] => 2的字母数字
[7] => A
[8] => s
[9] => f
[10] => f
[11] => 4
[12] => 5
[13] => d和中文_分割?
)
$arr = preg_split("/([a-zA-Z0-9]+)/", $str, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
print_r($arr);Array
(
[0] => php
[1] => 如何将字 符串中
[2] => 322
[3] => 的字母数字
[4] => Asf
[5] =>
[6] => f45d
[7] => 和中文_分割?
)