I want to explode a string for all:
- whitespaces (\n \t etc)
- comma
- hyphen (small dash). Like this >> -
But this does not work:
$keywords = explode("\n\t\r\a,-", "my string");
How to do that?
I want to explode a string for all:
But this does not work:
$keywords = explode("\n\t\r\a,-", "my string");
How to do that?
... or if you don't like regexes and you still want to explode stuff, you could replace multiple characters with just one character before your explosion:
$keywords = explode("-", str_replace(array("\n", "\t", "\r", "\a", ",", "-"), "-",
"my string\nIt contains text.\rAnd several\ntypes of new-lines.\tAnd tabs."));
var_dump($keywords);
This blows into:
array(6) {
[0]=>
string(9) "my string"
[1]=>
string(17) "It contains text."
[2]=>
string(11) "And several"
[3]=>
string(12) "types of new"
[4]=>
string(6) "lines."
[5]=>
string(9) "And tabs."
}