note 76467 modified in function.preg-replace by danbrown

From: Date: Fri, 28 Nov 2008 19:54:05 +0000
Subject: note 76467 modified in function.preg-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147153@lists.php.net to get a copy of this message
Based on previous comment, i suggest ( this function already exist in php 6 ) <?php function unicode_decode($str){ return preg_replace( '#\\\u([0-9a-f]{4})#e', "unicode_value('\\1')", $str); } function unicode_value($code) { $value=hexdec($code); if($value<0x0080) return chr($value); elseif($value<0x0800) return chr((($value&0x07c0)>>6)|0xc0) .chr(($value&0x3f)|0x80); else return chr((($value&0xf000)>>12)|0xe0) .chr((($value&0x0fc0)>>6)|0x80) .chr(($value&0x3f)|0x80); } ?> [EDIT BY danbrown AT php DOT net: This function originally written by mrozenoer AT overstream DOT net.] --was-- Based on previous comment, i suggest ( this function already exist in php 6 ) function unicode_decode($str){ return preg_replace( '#\\\u([0-9a-f]{4})#e', "unicode_value('\\1')", $str); } function unicode_value($code) { $value=hexdec($code); if($value<0x0080) return chr($value); elseif($value<0x0800) return chr((($value&0x07c0)>>6)|0xc0) .chr(($value&0x3f)|0x80); else return chr((($value&0xf000)>>12)|0xe0) .chr((($value&0x0fc0)>>6)|0x80) .chr(($value&0x3f)|0x80); } http://php.net/manual/en/function.preg-replace.php

« previous php.notes (#147153) next »