如何在PHP中用多个分隔符拆分字符串?

omg*_*omg 25 php regex string split

"something here ; and there, oh,that's all!"

我想分裂它;,

所以处理后应该得到:

something here

and there

oh

that's all!
Run Code Online (Sandbox Code Playgroud)

med*_*iev 37

<?php

$pattern = '/[;,]/';

$string = "something here ; and there, oh,that's all!";

echo '<pre>', print_r( preg_split( $pattern, $string ), 1 ), '</pre>';
Run Code Online (Sandbox Code Playgroud)

更新了更新问题的答案:

<?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>';
Run Code Online (Sandbox Code Playgroud)

  • @EvilChookie:我正在发送多个参数,我只是习惯那样做。 (2认同)

Dev*_*tas 10

$result_array = preg_split( "/[;,]/", $starting_string );
Run Code Online (Sandbox Code Playgroud)