Page 1 of 1
exploding with an empty separator
Posted: Fri Oct 13, 2006 11:45 pm
by anjanesh
explode() doesn't accept an empty separator. Is there a workaround for this ?
Code: Select all
$arr = array();
$str = "12345";
for ($i=0; $i<strlen($str); $i++)
{
$arr[] = $str[$i];
}
print_r($arr);
Thanks
Posted: Fri Oct 13, 2006 11:51 pm
by feyd
str_split(), but you can access a string as an array of bytes already, so what does it matter?

Posted: Fri Oct 13, 2006 11:53 pm
by n00b Saibot
what's wrong wth that? or you are looking for an alternate/built-in solution?
Posted: Sat Oct 14, 2006 5:16 am
by anjanesh
Ah...PHP 5's str_split ! Thanks.
but you can access a string as an array of bytes already, so what does it matter?
I want to use a number of array specific functions like array_unique etc on the string.
what's wrong wth that? or you are looking for an alternate/built-in solution?
With so many functions like explode, split etc I thought there already is some built-in one. Just didn't check for PHP5-only ones.
Posted: Sat Oct 14, 2006 11:35 am
by Chris Corbyn
anjanesh wrote:Ah...PHP 5's str_split ! Thanks.
but you can access a string as an array of bytes already, so what does it matter?
I want to use a number of array specific functions like array_unique etc on the string.
what's wrong wth that? or you are looking for an alternate/built-in solution?
With so many functions like explode, split etc I thought there already is some built-in one. Just didn't check for PHP5-only ones.
Code: Select all
$str = 'foobar123';
$letters = array();
for ($i = 0, $len = strlen($str); $i < $len; $i++)
{
$letters[] = $str[$i];
}