我如何在 php 中编码和解码来自 IDN 的 url?

发布于 2024-09-08 19:26:58 字数 1010 浏览 2 评论 0原文

我正在做一个网站来检查、注册域名等,我必须使其符合 IDN。 现在我有这样的东西:

echo $domain;       
$domain = idn_to_ascii($domain);
echo $domain;
$domain = idn_to_utf8($domain);
echo $domain;

我得到这个:

testing123ásd123 xn--testing123sd123-wjb 测试123ĂĄsd123

,你可以看到解码后的字符串与原始字符串不同,我也尝试使用 的类http://phlymail.com/en/downloads/idna/download/ 来做到这一点,我得到了与

我尝试使用的相同的结果:

$charset="UTF-8";
echo $domain;       
$domain = idn_to_ascii($domain, $charset);
echo $domain;
$domain = idn_to_utf8($domain);
echo $domain;

并且我得到了完全相同的结果(除了编码的字符串略有不同)

有什么想法吗?

编辑: 问题解决了!与此 转换字符串时出现问题到 puny 代码(在 PHP 中,使用 phlyLabs 的 punycode 字符串转换器) 原始字符串在 iso-8859-2 中并以 UTF-8 解码,现在我需要找到如何再次使其为 iso-8859-2 但谷歌可以帮助我。 有模组吗?我该怎么办?关闭它,删除它吗?就这样留下来吗?

im doing a site to check, register, etc of domains, i have to make it IDN compliant.
Right now i have something like this:

echo $domain;       
$domain = idn_to_ascii($domain);
echo $domain;
$domain = idn_to_utf8($domain);
echo $domain;

and im getting this:

testing123ásd123
xn--testing123sd123-wjb
testing123ĂĄsd123

as you can see the decoded string isnt the same as the original i also tried using a class by http://phlymail.com/en/downloads/idna/download/ to do it and im getting the same results

i have tried using:

$charset="UTF-8";
echo $domain;       
$domain = idn_to_ascii($domain, $charset);
echo $domain;
$domain = idn_to_utf8($domain);
echo $domain;

and i got exactly the same (except that the encoded string is slightly different)

any ideas?

EDIT:
Problem solved! with this Problem in converting string to puny code (in PHP, using phlyLabs's punycode string converter)
the original string was in iso-8859-2 and the decoded in UTF-8, now i need to find how to make it iso-8859-2 again but google can help me with that.
Any mods? what should i do with the question? close it, erase it? leave it this way?

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

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

发布评论

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

评论(1

时间海 2024-09-15 19:26:58

正如您已经指出的,ĂĄ 似乎是非 UTF8 文档中显示的 á 字符的 UTF8 表示形式。

您可以使用 iconv() 在字符集之间进行转换。但是,请注意,非 Unicode 字符集无法表示完整的国际字符集,因此必须将缺失的字符转换为 HTML 实体。例如:

<?php

$domain = idn_to_utf8($domain);
echo htmlentities($domain, ENT_COMPAT, 'UTF-8');

?>

无论如何,在整个项目中使用 UTF-8 可能会更容易。

As you already point out, ĂĄ appears to be the UTF8 representation of the á character as displayed in a non-UTF8 document.

You can use iconv() to convert between charsets. However, be aware that charsets that are not Unicode cannot represent the full set of international characters so must convert missing chars to HTML entities. E.g.:

<?php

$domain = idn_to_utf8($domain);
echo htmlentities($domain, ENT_COMPAT, 'UTF-8');

?>

In any case, it'd probably be easier to just use UTF-8 for the whole project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文