In javascript, var myStringToArray = myString.split('');
is perfectly acceptable.
But in PHP, $My_String_To_Array = explode('', $My_String);
throws an error:
Warning: explode() Empty delimiter
The PHP manual (http://php.net/manual/en/function.explode.php) explains:
If delimiter is an empty string (""), explode() will return FALSE.
So what should I be using in contemporary PHP instead of explode('', $My_String)
?
So far, the alternatives I can see are:
split("", $My_String)
- deprecated as of PHP 5.3.0str_split($My_String)
preg_split('//', $My_String)
Seven years ago, str_split()
would have been the correct alternative to use.
But is str_split()
still in contemporary usage or should I only be looking at preg_split()
?
Or should I be looking at something else?