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

2021-12-28 00:00:00 string regex split php

这里有东西;还有,哦,仅此而已!"

我想用;,

所以处理后应该得到:

something here

and there

oh

that's all!

推荐答案

<?php

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

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

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

更新了一个更新问题的答案:

Updated answer to an updated question:

<?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>';

相关文章