Logo

Programming-Idioms

History of Idiom 49 > diff from v36 to v37

Edit summary for version 37 by ancarda:
[PHP] Use single quotes for higher performance

Version 36

2019-02-02, 02:03:06

Version 37

2019-09-26, 22:20:46

Idiom #49 Split a space-separated string

Build list chunks consisting in substrings of input string s, separated by one or more space characters.

Illustration

Idiom #49 Split a space-separated string

Build list chunks consisting in substrings of input string s, separated by one or more space characters.

Illustration
Code
$chunks = preg_split("/ +/", $s);
Code
$chunks = preg_split('/ +/', $s);
Comments bubble
To match one ore more spaces, use preg_split instead of explode.
Comments bubble
To match one ore more spaces, use preg_split instead of explode.
Doc URL
http://php.net/manual/en/function.preg-split.php
Doc URL
http://php.net/manual/en/function.preg-split.php