Wednesday 15 January 2014

regex - How to split a string at 2 or more consecutive spaces in PHP -


I have a question at the end that has not been answered on the stack overflow for PHP already.

I need it in city, state, looking at the string to save zip in different variables

  $ new = "Palm dessert SD 63376"   

I am trying to strip the places which are grouped in 2 or more so that I can understand a city 2 words when it is considered, but all my searches or So show how a string is divided into a different language (java), or Of how to divide the space, which I can not.

I'm trying to use $ addr = preg_split ('#. * * (? = \ S {2,}) #', $ new );

But I can not find a string partition between Palm desserts and "SD63376" Please help!

You can use the following:

  $ str = "Palm Desert SD 63376"; // Note that the ragex pattern var_dump has two locations (preg_split ('~ + ~', $ str, -1, PREG_SPLIT_NO_EMPTY));   

Output:

  array (2) {[0] = & gt; String (11) "Palm desserts" [1] = & gt; String (7) "SD63376"}    

No comments:

Post a Comment