UCS2/HexEncoded karakterler

2 Cevap php

Biri bana yardımcı olabilir? nasıl UCS2/HexEncoded karakter alabilir

gibi 'Merhaba' "00480065006C006C006F geri döner"

Bu HexEncoded değerler şunlardır:

0048 = H 0065 = e 006C = l 006C = l 006F = o*

Ayrıca arapça (! مرحبا عالم) 06450631062d0628064b06270020063906270644064500200021 dönecektir

Nasıl php kodlanmış UCS2 alabilirim?

2 Cevap

mb_convert_encoding($str, 'UCS-2', 'auto') dize dönüştürmek için düzgün çalışır, ancak bir tarayıcıda doğru çıktı almak için fazladan iş yapmak zorunda olacak.

Bunu bir sayfaya çıktı echo kullanmak edebilmek için UCS-2 maç için çıkış karakter kümesini değiştirmek gerekir. Ayrıca, siz de başlığında bir meta etiketi aracılığıyla Content-Type ayarlamanız gerekebilir.

Ben şu unicode varyantları burada üç örnek verdim: UCS-2, UTF-16 ve UTF-8; hepsi Internet Explorer'da verdiği olmadan benim için çalıştı değil. Eğer doğru sonuç almak için UTF-8 PHP dosyaları saklamak gerekebilir. Ayrıca, Windows'un İngilizce sürümü üzerinde am, bu yüzden doğru RTL forma arapça dize giremezsiniz. Dizenizin burada bozuluyor üzgünüm. Benim yorumlarla kaydetti konuma değiştirin eğer, doğru sonuç alırsınız sizi temin ederim. Son olarak, internet UCS-2 ve UTF-16 görüntülemede sorun olabilir kaşif-orada çıktı önbellek aracılığıyla yeniden zaman bazı tuhaflıklar gibi görünüyor. Ancak, Firefox 3.5.5 üç kodlamaları için çalıştı. Bir uygulamayı yapma konusunda ciddi iseniz, ben şiddetle yerine UCS-2 UTF-8 kullanarak düşünün öneririz.

UCS-2 Version

FireFox 3.5.5 (Ok, but FireFox says it is UTF-16BE on my test.)
Internet Explorer 7.0 (Not Ok. Didn't detect/convert Arabic properly.)

<?php
header('Content-Type: text/html; charset=UCS-2');
mb_http_output('UCS-2');
echo mb_convert_encoding('<html><head><meta http-equiv="Content-Type" content="text/html; charset=UCS-2" /></head><body>', 'UCS-2', 'auto');
echo mb_convert_encoding('encoding: ', 'UCS-2', 'auto');
echo mb_convert_encoding(mb_http_output(), 'UCS-2', 'auto');
echo mb_convert_encoding('<br />', 'UCS-2', 'auto');
// NOTE: Replace the string here with your phrase
$strTerm = '!مرحبا عالم';
echo mb_convert_encoding('$strTerm = '.$strTerm.'<br />', 'UCS-2', 'auto');
echo mb_convert_encoding('query string: '.$_SERVER['QUERY_STRING'].'<br />', 'UCS-2', 'auto');
echo mb_convert_encoding('original hex: '.bin2hex($strTerm).'<br />', 'UCS-2', 'auto');
echo mb_convert_encoding('transformed hex: '.bin2hex(mb_convert_encoding($strTerm, 'UCS-2', 'auto')).'<br />', 'UCS-2', 'auto');
echo mb_convert_encoding('</body>', 'UCS-2', 'auto');
?>

UTF-16 Version

FireFox 3.5.5 (100% Ok)
Internet Explorer 7.0 (Fail. May have to specify Byte-Order.)

<?php
header('Content-Type: text/html; charset=UTF-16');
mb_http_output('UTF-16');
echo mb_convert_encoding('<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-16" /></head><body>', 'UTF-16', 'auto');
echo mb_convert_encoding('encoding: ', 'UTF-16', 'auto');
echo mb_convert_encoding(mb_http_output(), 'UTF-16', 'auto');
echo mb_convert_encoding('<br />', 'UTF-16', 'auto');
// NOTE: Replace the string here with your phrase
$strTerm = '!مرحبا عالم';
echo mb_convert_encoding('$strTerm = '.$strTerm.'<br />', 'UTF-16', 'auto');
echo mb_convert_encoding('query string: '.$_SERVER['QUERY_STRING'].'<br />', 'UTF-16', 'auto');
echo mb_convert_encoding('original hex: '.bin2hex($strTerm).'<br />', 'UTF-16', 'auto');
echo mb_convert_encoding('transformed hex: '.bin2hex(mb_convert_encoding($strTerm, 'UTF-16', 'auto')).'<br />', 'UTF-16', 'auto');
echo mb_convert_encoding('</body>', 'UTF-16', 'auto');
?>

UTF-8

FireFox 3.5.5 (100% Ok)
Internet Explorer 7.0 (100% Ok)

<?php
header('Content-Type: text/html; charset=UTF-8');
mb_http_output('UTF-8');
echo mb_convert_encoding('<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>', 'UTF-8', 'auto');
echo mb_convert_encoding('encoding: ', 'UTF-8', 'auto');
echo mb_convert_encoding(mb_http_output(), 'UTF-8', 'auto');
echo mb_convert_encoding('<br />', 'UTF-8', 'auto');
// NOTE: Replace the string here with your phrase
$strTerm = '!مرحبا عالم';
echo mb_convert_encoding('$strTerm = '.$strTerm.'<br />', 'UTF-8', 'auto');
echo mb_convert_encoding('query string: '.$_SERVER['QUERY_STRING'].'<br />', 'UTF-8', 'auto');
echo mb_convert_encoding('original hex: '.bin2hex($strTerm).'<br />', 'UTF-8', 'auto');
echo mb_convert_encoding('transformed hex: '.bin2hex(mb_convert_encoding($strTerm, 'UTF-8', 'auto')).'<br />', 'UTF-8', 'auto');
echo mb_convert_encoding('</body>', 'UTF-8', 'auto');
?>

this web page göre, Multi-Byte Dize modülü (Mbstring) UCS-2 destekler. Bu modül etkinleştirdikten sonra, diğer bir kodlama bir dize dönüştürmek için işlevi mb_convert_encoding kullanabilirsiniz.

Alıntı documentation of the mb_convert_encoding function:

string mb_convert_encoding  ( string $str  , string $to_encoding  [, mixed $from_encoding  ] )
Converts the character encoding of string str to to_encoding from optionally from_encoding .