Re: Re: exploding
| From: | Peter Brodersen | Date: | Wed, 25 Aug 2004 23:07:16 +0000 |
| Subject: | Re: Re: exploding | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-194741@lists.php.net to get a copy of this message | ||
On Thu, 26 Aug 2004 00:57:43 +0200, in php.general
felix.wesselmann@gmail.com (Felix) wrote:
>$array = explode( ' ', chunk_split( $sting, 1, ' ' ) );
>
>http://www.php.net/manual/de/function.explode.php
>http://www.php.net/manual/de/function.chunk-split.php
Well, that would leave a blank entry end of the array:
array(6) {
[0]=>
string(1) "0"
[1]=>
string(1) "0"
[2]=>
string(1) "0"
[3]=>
string(1) "0"
[4]=>
string(1) "8"
[5]=>
string(0) ""
}
Besides, strings containing spaces could also produce unexpected
results (like "foo bar baz"):
array(14) {
[0]=>
string(1) "f"
[1]=>
string(1) "o"
[2]=>
string(1) "o"
[3]=>
string(0) ""
[4]=>
string(0) ""
[5]=>
string(1) "b"
[6]=>
string(1) "a"
[7]=>
string(1) "r"
[8]=>
string(0) ""
[9]=>
string(0) ""
[10]=>
string(1) "b"
[11]=>
string(1) "a"
[12]=>
string(1) "z"
[13]=>
string(0) ""
}
I would still suggest str_split() if available, otherwise
preg_split().
--
- Peter Brodersen