跳至
function utf8_to_unicode($str)
{//来自:http://www.cnblogs.com/niniwzw/archive/2010/12/17/1909534.html
$mState = 0; // cached expected number of octets after the current octet
// until the beginning of the next UTF8 character sequence
$mUcs4 = 0; // cached Unicode character
$mBytes = 1; // cached expected number of octets in the current sequence
$out = array();
$len = strlen($str);
for($i = 0; $i 0x10FFFF)) {
trigger_error(
'utf8_to_unicode: Illegal sequence or codepoint '.
'in UTF-8 at byte '.$i,
E_USER_WARNING
);
return FALSE;
}
if (0xFEFF != $mUcs4) {
// BOM is legal but we don't want to output it
$out[] = $mUcs4;
}
//initialize UTF8 cache
$mState = 0;
$mUcs4 = 0;
$mBytes = 1;
}
} else {
/**
*((0xC0 & (*in) != 0x80) && (mState != 0))
* Incomplete multi-octet sequence.
*/
trigger_error(
'utf8_to_unicode: Incomplete multi-octet '.
' sequence in UTF-8 at byte '.$i,
E_USER_WARNING
);
return FALSE;
}
}
}
return $out;
}