如何使用 PHP 将阿拉伯文本转换为十六进制

发布于 12-27 23:02 字数 110 浏览 5 评论 0原文

请注意,我需要将阿拉伯文本与十六进制相互转换,如下例所示使用 PHP

мыба

06450631062D06280627

问候,

Eco

Kindly I need to convert the Arabic text to and from Hexadecimal like the following example Using PHP

مرحبا

06450631062D06280627

Regards,

Eco

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

那支青花2025-01-03 23:02:20

如果您只需要开始生成 HTML 文档中写入的阿拉伯文本,我认为最简单的方法是将序列转换为字符引用,例如将 0645 转换为 م。这可以按如下方式完成:

<?php
$str = '06450631062D06280627';
for($i = 0; $i < strlen($str)/4; $i++) {
  echo "&#x", substr($str, 4*$i, 4), ";";
}
?>

If you just need to have the Arabic text written in the HTML document begin generated, I think the simplest way is to convert the sequence to character references, turning e.g. 0645 to م. This could be done as follows:

<?php
$str = '06450631062D06280627';
for($i = 0; $i < strlen($str)/4; $i++) {
  echo "&#x", substr($str, 4*$i, 4), ";";
}
?>
人生戏2025-01-03 23:02:20

我得到一个带有以下代码的 unicode 字符串。

$str = "Some Hexa String";
$replacedString = preg_replace("/\\\\u([0-9abcdef]{4})/", "&#x$1;", $str);
$unicodeString = mb_convert_encoding($replacedString, 'UTF-8', 'HTML-ENTITIES');

I get a unicode string with following code.

$str = "Some Hexa String";
$replacedString = preg_replace("/\\\\u([0-9abcdef]{4})/", "&#x$1;", $str);
$unicodeString = mb_convert_encoding($replacedString, 'UTF-8', 'HTML-ENTITIES');
云淡风轻2025-01-03 23:02:20
bin2hex($str);       // Bin to Hex
pack("H*", $hexStr); // Hex to Bin
bin2hex($str);       // Bin to Hex
pack("H*", $hexStr); // Hex to Bin
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文