本文介绍了如何编码西里尔字符的URL,然后解码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个页面上有一个表单:

I have a form on one page:

<form method="POST" accept-charset="UTF-8" action="index.cgi" name="TestForm">

其中一个输入字段search_string可用于发送西里尔字符,字符串如下所示:

One of the input fields "search_string" may be used to send Cyrillic characters and if that happens the URL string looks like this:

search_string=%41F%2F%424+%41F%41E%414%416%410%420%41A%410+%418%417+%421%412%418%41D

推荐答案

正确的解决方案,包括空格:

Correct solution, including spaces:

use open ':std', ':encoding(UTF-8)';
use Encode;

my $escaped = '%41F%2F%424+%41F%41E%414%416%410%420%41A%410+%418%417+%421%412%418%41D';
(my $unescaped = $escaped) =~ s/\+/ /g;
$unescaped =~ s/%([[:xdigit:]]+)/chr hex $1/eg;
print $unescaped;
# П/Ф ПОДЖАРКА ИЗ СВИН

Credit转到首先识别这些是以为前缀的Unicode代码点。

Credit goes to Renaud Bompuis for recognising as the first that these are Unicode code-points prefixed with %.

我想补充一点,这个问题的编码方案非常不寻常,我以前没有见过。通常,人们期望字符串П/ФПОДЖАРКАИЗСВИН被编码为%D0%9F%2F%D0%A4 +%D0%9F %D0%9E%D0%94%D0%96%D0%90%D0%A0%D0%9A%D0%90 +%D0%98%D0%97 +%D0%A1%D0%92%D0%98 %D0%9D ,也就是说,首先将字符编码为UTF-8,然后八位字节进行百分比转义。此方案适用于的答案。

I wish to add that the encoding scheme from the question is very unusual, I haven't seen it before. Normally one would expect the characters string П/Ф ПОДЖАРКА ИЗ СВИН to be encoded as %D0%9F%2F%D0%A4+%D0%9F%D0%9E%D0%94%D0%96%D0%90%D0%A0%D0%9A%D0%90+%D0%98%D0%97+%D0%A1%D0%92%D0%98%D0%9D, that is to say, first the characters are encoded into UTF-8, then the octets are percent-escaped. This scheme works with the answer from Dr.Kameleon.

这篇关于如何编码西里尔字符的URL,然后解码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 18:46