note 107698 added to function.mb-substr
| From: | qeremy | Date: | Mon, 27 Feb 2012 15:58:56 +0000 |
| Subject: | note 107698 added to function.mb-substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186398@lists.php.net to get a copy of this message | ||
A proper (logical) alternative for unicode strings;
<?php
function substr_unicode($str, $s, $l = null) {
return join("", array_slice(
preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY), $s, $l));
}
$str = "Büyük";
$s = 0; // start from "0" (nth) char
$l = 3; // get "3" chars
echo substr($str, $s, $l) ."\n"; // Bü
echo mb_substr($str, $s, $l) ."\n"; // Bü
echo substr_unicode($str, $s, $l); // Büy
?>
----
Server IP: 69.147.83.197
Probable Submitter: 194.27.149.90
----
Manual Page -- http://www.php.net/manual/en/function.mb-substr.php
Edit -- https://master.php.net/note/edit/107698
Del: integrated -- https://master.php.net/note/delete/107698/integrated
Del: useless -- https://master.php.net/note/delete/107698/useless
Del: bad code -- https://master.php.net/note/delete/107698/bad+code
Del: spam -- https://master.php.net/note/delete/107698/spam
Del: non-english -- https://master.php.net/note/delete/107698/non-english
Del: in docs -- https://master.php.net/note/delete/107698/in+docs
Del: other reasons-- https://master.php.net/note/delete/107698
Reject -- https://master.php.net/note/reject/107698
Search -- https://master.php.net/manage/user-notes.php