隔着每个字爆炸 [英] Explode over every other word

查看:81
本文介绍了隔着每个字爆炸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我说一个字符串:

$string = "This is my test case for an example."

如果我基于''爆炸,我会得到一个

If I do explode based on ' ' I get an

Array('This','is','my','test','case','for','an','example.');

我想要的是爆炸其他所有空间:

What I want is an explode for every other space:

Array('This is','my test','case for','an example.').

该字符串可能包含奇数个单词,因此数组中的最后一项可能不包含两个单词.

The string may have an odd # of words, so the last item in the array may not contain two words.

有人知道该怎么做吗?

推荐答案

我将仔细检查结果,并在事实之后串联字符串.

I would look through the results, and concatenate the strings after the fact.

这篇关于隔着每个字爆炸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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