note 107698 deleted from function.mb-substr by cmb

From: Date: Tue, 30 Jun 2015 19:24:15 +0000
Subject: note 107698 deleted from function.mb-substr by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-203000@lists.php.net to get a copy of this message
Note Submitter: qeremy [atta] gmail [dotta] com ---- 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 ?>

« previous php.notes (#203000) next »