ARC2::toUTF8 PHP Method

toUTF8() static public method

*
static public toUTF8 ( $v )
    static function toUTF8($v)
    {
        if (urlencode($v) === $v) {
            return $v;
        }
        //if (utf8_decode($v) == $v) return $v;
        $v = strpos(utf8_decode(str_replace('?', '', $v)), '?') === false ? utf8_decode($v) : $v;
        /* custom hacks, mainly caused by bugs in PHP's json_decode */
        $mappings = array('%18' => '‘', '%19' => '’', '%1C' => '“', '%1D' => '”', '%1E' => '„', '%10' => '‐', '%12' => '−', '%13' => '–', '%14' => '—', '%26' => '&');
        $froms = array_keys($mappings);
        $tos = array_values($mappings);
        foreach ($froms as $i => $from) {
            $froms[$i] = urldecode($from);
        }
        $v = str_replace($froms, $tos, $v);
        /* utf8 tweaks */
        return preg_replace_callback('/([\\x00-\\xdf][\\x80-\\xbf]|[\\xe0-\\xef][\\x80-\\xbf]{2}|[\\xf0-\\xf7][\\x80-\\xbf]{3}|[\\xf8-\\xfb][\\x80-\\xbf]{4}|[\\xfc-\\xfd][\\x80-\\xbf]{5}|[^\\x00-\\x7f])/', array('ARC2', 'getUTF8Char'), $v);
    }

Usage Example

Ejemplo n.º 1
0
 public function testToUTF8()
 {
     $actual = ARC2::toUTF8('foo');
     $this->assertEquals('foo', $actual);
     $actual = ARC2::toUTF8(utf8_encode('Iñtërnâtiônàlizætiøn'));
     $this->assertEquals('Iñtërnâtiônàlizætiøn', $actual);
 }
All Usage Examples Of ARC2::toUTF8