PHP 爆炸排除
我有一个包含如下数据的字符串:
8487613 1298296324 1a6ad892e547da07f35221fdfe6f70dd“|MoDo|” 178.211.28.126“战地叛逆连队 2”“BC 内容和名称”“违规 (AIMBOT) #50246”
在我的 PHP 中,我使用如下爆炸:
$more_info = explode(' ', $banned_players);
但它分隔了“Battlefield Bad Company 2”中的空格,我不希望这样发生。
那么有没有什么办法可以用空格爆炸,但不在“”字符之间爆炸呢?
I have a string with data like this:
8487613 1298296324 1a6ad892e547da07f35221fdfe6f70dd "|MoDo|" 178.211.28.126 "Battlefield Bad Company 2" "BC Stuff and name" "Violation (AIMBOT) #50246"
In my PHP I use explode like this:
$more_info = explode(' ', $banned_players);
But it separates spaces in "Battlefield Bad Company 2" and I don't want that to happen.
So is there any way for explode with spaces but not between "" characters?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试str_getcsv()。它适用于制表符或逗号分隔值,但仅使用空格作为分隔符就可以很好地工作:
结果:
Try str_getcsv(). It's intended for tab- or comma-separated values, but it works very well with just the space as separator:
Results in:
使用
preg_split
代替Use
preg_split
instead分解“字符,你将得到3个数组,然后用空格字符分解第一个数组和最后一个数组,并使用
array_push()
和array_merge()
将它们全部合并。Explode the " character, you'll have 3 arrays, then explode first array and last array with space character, and use
array_push()
andarray_merge()
to merge them all.您可以使用
str_getcsv
和一个空格作为分隔符。注意:这只适用于只有一个字符分隔符的情况。
You could use
str_getcsv
with one whitespace as delimiter.Note: This only works, if you have only one character delimiters.