I have a form on one page:
<form method="POST" accept-charset="UTF-8" action="index.cgi" name="TestForm">
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
How do I decode this back to the original string on the page I post to?
Correct solution, including spaces:
Credit goes to Renaud Bompuis for recognising as the first that these are Unicode code-points prefixed with
%
.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.Try that in your script (
index.cgi
) :Then...
Another idea (if you want to create a UTF8-friendly hash of your CGI input) :
Taken from : http://ahinea.com/en/tech/perl-unicode-struggle.html
A solution that preserves the
+
and any other character in the original string:Result: