"something here ; and there, oh,that's all!"
我想把它分为;
和,
所以在处理之后应该得到:
something here
and there
oh
that's all!
发布于 2009-09-21 03:35:38
<?php
$pattern = '/[;,]/';
$string = "something here ; and there, oh,that's all!";
echo '<pre>', print_r( preg_split( $pattern, $string ), 1 ), '</pre>';
已更新问题的更新答案:
<?php
$pattern = '/[\x{ff0c},]/u';
//$string = "something here ; and there, oh,that's all!";
$string = 'hei,nihao,a ';
echo '<pre>', print_r( preg_split( $pattern, $string ), 1 ), '</pre>';
发布于 2009-09-21 03:34:55
$result_array = preg_split( "/[;,]/", $starting_string );
发布于 2009-09-21 03:39:24
PHP函数的split()允许分隔符为正则表达式。不幸的是,它已被弃用,并将在PHP7中删除!
preg_split()函数应该没问题,它返回一个数组:
$results = preg_split('/[;,]/', $string);
还有一些额外的可选参数可能对您有用。
您编辑的示例中的第一个分隔符字符实际上是一个2字节的Unicode字符吗?
也许preg_slit()函数将分隔符视为三个字符,并在unicode (中文?)‘字符’
https://stackoverflow.com/questions/1452777
复制相似问题