note 124158 added to function.preg-split
| From: | HayleyWatson@php.net | Date: | Sun, 01 Sep 2019 03:02:59 +0000 |
| Subject: | note 124158 added to function.preg-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-212039@lists.php.net to get a copy of this message | ||
Assuming you're using UTF-8, this function can be used to separate Unicode text into individual
codepoints without the need for the multibyte extension.
<?php
preg_split('//u', $text, -1, PREG_SPLIT_NO_EMPTY);
?>
The words "English", "Español", and "Ð ÑÑÑкий"
are all seven letters long. But strlen would report string lengths 7, 8 and 14, respectively. The
preg_split above would return a seven-element array in all three cases.
It splits 'íêµì´' into the array ['í', 'êµ',
'ì´'] instead of the 9-character array that str_split($text) would produce.
----
Server IP: 208.43.231.9
Probable Submitter: 101.0.109.162 (proxied: 122.58.132.37)
----
Manual Page -- http://php.net/manual/en/function.preg-split.php
Edit -- https://master.php.net/note/edit/124158
Del: integrated -- https://master.php.net/note/delete/124158/integrated
Del: useless -- https://master.php.net/note/delete/124158/useless
Del: bad code -- https://master.php.net/note/delete/124158/bad+code
Del: spam -- https://master.php.net/note/delete/124158/spam
Del: non-english -- https://master.php.net/note/delete/124158/non-english
Del: in docs -- https://master.php.net/note/delete/124158/in+docs
Del: other reasons-- https://master.php.net/note/delete/124158
Reject -- https://master.php.net/note/reject/124158
Search -- https://master.php.net/manage/user-notes.php