note 107697 deleted from function.substr by danbrown

From: Date: Thu, 10 May 2012 20:19:24 +0000
Subject: note 107697 deleted from function.substr by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187785@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 (#187785) next »