将单行编号列表拆分为平面数组
所以我试图分解一个包含答案列表的字符串。
1. Comb. 2. Thumb. 3. Tomb (catacomb). 4. Womb. 5. Crumb. 6. Bomb. 7. Numb. 8. Aplomb. 9. Succumb.
有没有办法将其分解为如下所示:
$answer = explode("something here", $answerString);
$answer[1] = 1. Comb.
$answer[2] = 2. Thumb.
$answer[3] = 3. Tomb (catacomb).
棘手的是我想分解这个字符串,以便每个答案都可以在数字之后分隔。
因此,如果答案是 1 个字符或 10 个单词,它仍然会在每个数字之前拆分。
So I'm trying to explode a string that has a list of answers.
1. Comb. 2. Thumb. 3. Tomb (catacomb). 4. Womb. 5. Crumb. 6. Bomb. 7. Numb. 8. Aplomb. 9. Succumb.
Is there a way to explode this to come out like the following:
$answer = explode("something here", $answerString);
$answer[1] = 1. Comb.
$answer[2] = 2. Thumb.
$answer[3] = 3. Tomb (catacomb).
The tricky thing is that I want to explode this string so that each answer can be separated after a number.
So, if the answer is 1 character, or 10 words, it will still split before each number.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不,这不可能用explode()实现,但是你可以使用
preg_split()
http://sandbox.phpcode.eu/g/4b041/1< /a>
No, this is not possible with explode(), but you can use
preg_split()
http://sandbox.phpcode.eu/g/4b041/1
您可能想使用
preg_split()
相反。像这样的东西:You probably want to use
preg_split()
instead. Something like:在数字前的可选空格上拆分,后跟一个点。
输出:
Split on the optional space before a number followed by a dot.
Output: