在两个分隔字符之一之前隔离前导字符串 [英] Isolate leading string before one of two delimiting characters

查看:12
本文介绍了在两个分隔字符之一之前隔离前导字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么好的方法可以在空格或点上分割字符串吗?

Is there any nice way to split an string on a space or a dot?

喜欢

$string = "test.test"
//result = test

$string = "test doe"
//result = test

当然我可以使用爆炸两次,但我确定这不是最好的解决方案;)

Sure I can use explode two times, but I am sure that's not the best solutions ;)

推荐答案

如果你想拆分几个不同的字符,看看 preg_split

If you want to split on several different chars, take a look at preg_split

//split string on space or period:
$split=preg_split('/[ \.]/', $string);

这篇关于在两个分隔字符之一之前隔离前导字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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