RE: [PHP-DEV] Re: foreach() for strings
| From: | John Crenshaw | Date: | Mon, 20 Jun 2011 20:01:30 +0000 |
| Subject: | RE: [PHP-DEV] Re: foreach() for strings | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-53449@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Anthony Ferrara [mailto:ircmaxell@gmail.com]
>
> > text_to_array($s) == str_split($s, 1)
>
> No, because str_split always splits into 1 byte chunks. text_to_array
> would take the character set into account (or that's where the utility
> in it would be)...
I think this does what you want:
function utf8_str_split($s)
{
return preg_split("/(.)/u", $s, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
}
John Crenshaw
Priacta, Inc.