0

我一直在寻找一种在每个空格上拆分字符串的方法,直到找到第二个冒号。如果对答案有帮助,我正在使用的语言是 PHP。基本上我想要的是以下字符串:

:foo!bar@cookie.net strawberry cheesecake :hello world: this is a message!

拆分为以下数组:

array(
    [0] => ":foo!bar@cookie.net",
    [1] => "strawberry",
    [2] => "cheesecake",
    [3] => ":hello world: this is a message!"
);

我将如何实现这一目标?请注意,不保证冒号存在。输入字符串可能不同,例如Hello World.

4

1 回答 1

0

您将首先在冒号上拆分。然后在空间上拆分第一个

例子

$colon = explode(",",$str);
$space = explode(" ",$colon[1]);

然后冒号 [2] 将有其余的字符串,而空格将有空格分隔的部分

于 2013-09-10T23:27:55.897 回答