Tuesday, October 26, 2010

PHP Issue :: preg_split instead of explode function

If the need is to parse a string and extract the words. Then its advisable to use preg_split instead of using the explode function.

Code follows :
preg_split ("/\s+/",$textInput);
where the first argument is the regular expression for finding one or more spaces and the second argument is the input text.

This option works far better than the explode(" ", $textInput).

No comments: