UTF-8の文字列をユニコードに変換する簡単な方法はありますか? 私が基本的にしようとしているのは、 'è'を '00E8'に変換することです。PHP - UTF-8からUnicodeヘキサへの変換
0
A
答えて
1
あなたはそれを行うためにjson_encode
を使用することができます...
$str = "è";
$str = json_encode($str);
print $str;
これをu00e8 \印刷します。あなたは、あなたが望むなら、あなたは\ uを取り除くためにstr_replace
することができます。 eの代わりにEが必要な場合は、strtoupper
を使用できます。ここで
0
が、私はそれを試してみたが、それはASCII文字では動作しません、私は
/**
* Display utf && non-printable characters as hex
*
* @param string $str string containing binary
* @param boolean $htmlout add html markup?
*
* @return string
*/
public function strInspect($str)
{
$this->htmlout = $htmlout;
$regex = <<<EOD
/
([\x01-\x7F]) # single-byte sequences 0xxxxxxx (ascii 0 - 127)
| (
(?: [\xC0-\xDF][\x80-\xBF] # double-byte sequences 110xxxxx 10xxxxxx
| [\xE0-\xEF][\x80-\xBF]{2} # triple-byte sequences 1110xxxx 10xxxxxx * 2
| [\xF0-\xF7][\x80-\xBF]{3} # quadruple-byte sequence 11110xxx 10xxxxxx * 3
){1,100} # ...one or more times
)
| ([\x80-\xBF]) # invalid byte in range 10000000 - 10111111 128 - 191
| ([\xC0-\xFF]) # invalid byte in range 11000000 - 11111111 192 - 255
| (.) # null (including x00 in the regex = fail)
/x
EOD;
$str_orig = $str;
$strlen = strlen($str);
$str = preg_replace_callback($regex, 'strInspectCallback', $str);
return $str;
}
/**
* Callback used by strInspect's preg_replace_callback
*
* @param array $matches matches
*
* @return string
*/
protected function strInspectCallback($matches)
{
$showHex = false;
if ($matches[1] !== '') {
// single byte sequence (may contain control char)
$str = $matches[1];
if (ord($str) < 32 || ord($str) == 127) {
$showHex = true;
if (in_array($str, array("\t","\n","\r"))) {
$showHex = false;
}
}
} elseif ($matches[2] !== '') {
// Valid byte sequence. return unmodified.
$str = $matches[2];
$sequences = array(
"\xef\xbb\xbf", // BOM
"\xc2\xa0", // no-break space
// "\xE2\x80\x89", // thin space
// "\xE2\x80\xAF", // narrow no-break space
"\xEF\xBF\xBD", // "Replacement Character"
);
foreach ($sequences as $seq) {
if ($str === $seq) {
$showHex = true;
break;
}
}
} elseif ($matches[3] !== '' || $matches[4] !== '') {
// Invalid byte
$str = $matches[3] != ''
? $matches[3]
: $matches[4];
$showHex = true;
} else {
// null char
$str = $matches[5];
$showHex = true;
}
if ($showHex) {
$chars = str_split($str);
foreach ($chars as $i => $c) {
$chars[$i] = '\x'.bin2hex($c);
}
$str = implode('', $chars);
}
return $str;
}
関連する問題
- 1. UTF8からJavaのASCIIへの変換
- 2. LinuxのEBCDICからUTF8への変換
- 3. UTF8からASCIIへの変換
- 4. Mongodbからutf8への変換
- 5. 文字列からUnicodeへの変換
- 6. C#からjavascriptへのUnicode変換
- 7. UTF-8からUnicodeへの変換
- 8. Unicode(16進)からvarcharへの変換
- 9. txtファイルの非UnicodeからUnicodeへの変換
- 10. windows-1255からUTF8へのajax応答の変換
- 11. DOS737からUTF8へのtxtファイルのエンコーディングを変換する
- 12. どのようにutf8をunicodeからactionscriptに変換するのですか?
- 13. PHP - UTF8へのエンコーディングの変換が機能しません。
- 14. iPhone - WindowsCP1251からUTF8へのNSStringエンコードの変換
- 15. C#ASPからutf8へのパラメータの変換
- 16. UTF8バイト[]から文字列への変換
- 17. json androidから受け取ったPHPのunicodeシーケンスをutf8に変換するには?
- 18. 一部のコードページからUnicodeへの文字列の変換
- 19. PythonのUnicode文字列からASCIIへの変換2.7
- 20. C#UTF8からAESからBase64への変換のペイロード前のジャンクバイト
- 21. PHPをutf8(195 134)から198に変換する
- 22. Unicode文字列から日付形式への変換エラー
- 23. UnicodeからISO8859-2へのDB2コード変換
- 24. Pythonの安全なUnicodeへの変換
- 25. JSからPHPへの変換関数
- 26. C++からPHPへの変換
- 27. pythonからphpへの変換
- 28. PHP UTF-16からASCIIへの変換
- 29. php mysql_real_escape_stringからmysqliへの変換
- 30. ASP.NETからPHPへの配列変換
鉱山のデバッグクラスから変更少し何か、私は基本的に変換するために何かを探しています言うことができます:Hがに0048、00E8までのように。 – Kwyjibo