Wednesday 15 September 2010

arrays - split string by any amount of whitespace in PHP -


I know how to split the string so that the words between the delimiter "elements in an array" include ".explode" .

But it only splits the string with a single whitespace character, how can I divide it from any kind of white space?

Then when an element gets the whitespace at the end of the array and the next element in Aram starts when the character of non-white space is found for the first time.

Then something like the "quick brown fox" turns into an array, the elements in the array quickly, brown, and fox returned.

And "jump on lazy dog" is also divided, so each word returned has a different element in the array.

like this:

  preg_split ('# \ s + # ', $ String, empty, PREG_SPLIT_NO_EMPTY);    

No comments:

Post a Comment