How do you split a string into word pairs?

Lictmeeliclon

New Member
I am trying to split a string into an array of word pairs in PHP. So for example if you have the input string:\[code\]"split this string into word pairs please"\[/code\]the output array should look like\[code\]Array ( [0] => split this [1] => this string [2] => string into [3] => into word [4] => word pairs [5] => pairs please [6] => please)\[/code\]some failed attempts include:\[code\]$array = preg_split('/\w+\s+\w+/', $string);\[/code\]which gives me an empty array, and\[code\]preg_match('/\w+\s+\w+/', $string, $array);\[/code\]which splits the string into word pairs but doesn't repeat the word. Is there an easy way to do this? Thanks.
 
Back
Top