i have a string like below:
صفحه نخست - خبرآنلاین
شنبه 20 مهر 1392 - 04:18
data-val-required کلمه مورد جستجو الزامی است. id Keyword name Keyword type text value
i tried to make an array of words by preg_split
but i need some helps on regular expression.
i used preg_split('/ {1,}/', $text);
but it dont covered all spaces....
some new lines are in my final array..
i can to clean up array after the finish of the string by trim
and unset
the array element but before it i have to look for a better regular expression.
what is the best regular expression format for me!?
You can use \s+
to match one or more empty spaces, which includes newlines.
Also, you could add a fourth parameter PREG_SPLIT_NO_EMPTY
to exclude any matching spaces.
$foo = preg_split ("/\s+/", $text, 0, PREG_SPLIT_NO_EMPTY);
For more information, see preg_split().