如何在 Perl 中 URI 转义日语字符?

发布于 2024-09-26 06:30:01 字数 29 浏览 0 评论 0原文

如何在 Perl 中 URI 转义日语字符?

How do I URI escape Japanese characters in Perl?

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

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

发布评论

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

评论(2

断念 2024-10-03 06:30:01

URI::Escape 模块将能够处理日语字符,就像 URI 中的任何其他不安全或特殊字符一样。

一般来说,当您在 Perl 中寻找某些功能时,尤其是一些看起来像在 URI 中转义某些内容一样常见的功能,您应该参考 首先http://search.cpan.org。当搜索您在问题中使用的任何关键字时,URI::Escape 可能位于结果的最顶部。

The URI::Escape module will be able to handle japanese characters, just like any other unsafe or special character un URIs.

Generally, when you're looking for some functionality in Perl, especially some that would seem as common as escaping things in URIs, you should consult http://search.cpan.org first. URI::Escape would probably have been at the very top of the results when searching for any of the keywords you used in your question.

笑脸一如从前 2024-10-03 06:30:01

如何在 Perl 中对 URI 转义日语字符?

您需要提及日语字符的编码方式。

如果您使用 UTF-8 并且还使用 Perl 的内置 Unicode 编码,那么您可以使用以下内容:

 use utf8;
 use URI::Escape qw/uri_escape_utf8/;
 my $escaped = uri_escape_utf8 ("チャオ");

如果您的日语字符使用某种格式进行编码,例如 EUC-JP、Shift -JIS,或者其他类似的东西,你需要指定你需要什么样的URI转义。标准的东西

 my $escaped = uri_escape ("ハロー");

会给你一些 URI 编码的东西,但它对另一端不一定有意义。例如,如果您正在为 WWWJDIC 创建 URL,则对于 UTF-8,要查找渮的 URI 是这样的:

http://www.csse.monash.edu.au/~jwb/cgi-bin/wwwjdic.cgi?1MMJ%E6%B8%AE

但对于 EUC-JP,同一页面如下所示:

http://www.csse.monash.edu.au/~jwb/cgi-bin/wwwjdic.cgi?1MKJ%DE%D1

Perl 将为您执行任一操作,但您需要具体说明你的出发点是什么。

How do I URI escape Japanese characters in Perl?

You need to mention what encoding the Japanese characters are in.

If you are using UTF-8 and also using Perl's built-in Unicode encoding, then you can use this:

 use utf8;
 use URI::Escape qw/uri_escape_utf8/;
 my $escaped = uri_escape_utf8 ("チャオ");

If your Japanese characters are encoded using some format like EUC-JP, Shift-JIS, or other such things, you need to specify what kind of URI escaping you require. The standard things like

 my $escaped = uri_escape ("ハロー");

will give you something which is URI encoded but it isn't necessarily meaningful to the other end. For example if you are making a URL for WWWJDIC, the URI to look up 渮 is this for UTF-8:

http://www.csse.monash.edu.au/~jwb/cgi-bin/wwwjdic.cgi?1MMJ%E6%B8%AE

But for EUC-JP the same page looks like this:

http://www.csse.monash.edu.au/~jwb/cgi-bin/wwwjdic.cgi?1MKJ%DE%D1

Perl will do either one for you but you need to be specific about what your starting point is.

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