php - Split string by white-space -


How can I divide a string from white space, it is not known how long the white space is?

For example, with the following string:

  "Quick brown fox jumps on lazy dogs"   

I will get an array

  ['The', 'Quick', 'Brown', 'Fox', 'Jumps', 'Over', 'D', 'Lazy', 'Dog'];    

You can use regular expressions to do this easily:

  $ string = 'Quick brown fox jumps over lazy dogs'; $ Word = preg_split ('/ \ s + /', $ string, -1, PREG_SPLIT_NO_EMPTY); Print_r (word $);   

This produces this output:

  array ([0] => [1] => immediately [2] = & gt; Brown [3] => Fox [4] = & gt; Jump [5] => Over [6] => [7] => Lazy [8] = & gt; Dog)    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -