如何在PHP中用多个分隔符分割字符串? [英] How to split a string by multiple delimiters in PHP?

查看:78
本文介绍了如何在PHP中用多个分隔符分割字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我想按;,

因此处理后应该得到:

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

这篇关于如何在PHP中用多个分隔符分割字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆