Sangwal’s Weblog

Just another WordPress.com weblog

Splitting a unicode string into individual characters in PHP

leave a comment »

I had a hard time finding something that can easily split a unicode string into individual unicode characters. Finally, I find something here http://bugs.php.net/bug.php?id=27103 that gave a straightforward method to do the splitting. Here is the code:

$s = "यहां पर एक युनिकोड लड़ी (string) डालें";

print "<pre>";
print_r( preg_split("//u", $s, -1, PREG_SPLIT_NO_EMPTY));
print "</pre>";

The above code will output the individual letters in the string $s. Feel free to adapt to it your needs. Cheers!

Written by sangwal

March 19, 2008 at 5:23 pm

Posted in Uncategorized

Tagged with , , ,

Leave a Reply