note 109054 deleted from function.chr by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 Jun 2012 14:32:01 +0000 |
| Subject: | note 109054 deleted from function.chr by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-188654@lists.php.net to get a copy of this message | ||
Note Submitter: sageptr at gmail dot com
----
Another UTF-8 compatible version of chr. Based on pure bitwise calculation, so faster than others:
<?php
function chr_utf8($code){
if($code < 128) return chr($code);
if($code < 0x7FF) return chr(192|($code>>6)).chr(128|($code&63));
if($code < 0xFFFF) return
chr(224|($code>>12)).chr(128|($code>>6)&63).chr(128|($code&63));
if($code < 0x1FFFFF) return
chr(240|($code>>18)).chr(128|($code>>12)&63).chr(128|($code>>6)&63).chr(128|($code&63));
}
?>