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

2022-08-30 13:37:47

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

我想将其拆分为;,

所以经过处理后应该得到:

something here

and there

oh

that's all!

答案 1
<?php

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

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

echo '<pre>', print_r( preg_split( $pattern, $string ), 1 ), '</pre>';

答案 2
$result_array = preg_split( "/[;,]/", $starting_string );

推荐