我可以帮你将一个字符串在PHP中拆分为单词对的数组。例如,如果你有以下输入字符串:
"split this string into word pairs please"
输出数组应该长成这个样子。
Array (
[0] => split this
[1] => this string
[2] => string into
[3] => into word
[4] => word pairs
[5] => pairs please
[6] => please
)
一些失败的尝试包括:
$array = preg_split('/\w+\s+\w+/', $string);
这会给我一个空数组。
preg_match('/\w+\s+\w+/', $string, $array);
有没有一种简单的方法可以将字符串分成单词对,但不重复单词?谢谢。