开发者

How to convert domain names with greek characters to an ascii URL?

开发者 https://www.devze.com 2023-01-16 15:45 出处:网络
For example: When typing παιχνιδια.com into Firefox, it is automatically convert开发者_运维百科ed to xn--kxadblxczv9d.com

For example:

When typing παιχνιδια.com into Firefox, it is automatically convert开发者_运维百科ed to xn--kxadblxczv9d.com

Please suggest a tool for making such a conversion.


One of the easiest is this. Converts and checks for availability at the same time.


If you want to do it inside your browser, save the code in this answer as puny.js and the code below to puny.html, then load the file in your browser.

<html>
    <title>Punyconverter</title>
    <script type="text/javascript" src="puny.js"></script>
    <style type="text/css">
        input {width:300px;}
        label {width:100px; display:inline-block;}
    </style>
    <script type="text/javascript">
        onload = function( ) {
            var ASCII = document.getElementById("ASCII");
            var Unicode = document.getElementById("Unicode");
            var Input = document.getElementById("Input");

            Input.onkeyup=function(){
                ASCII.value = punycode.ToASCII( this.value);
                Unicode.value = punycode.ToUnicode( this.value);
            }
        };
    </script>
</html>
<body>
    <h1>Convert puny coded IDN</h1>
    <div><label for="Input">Input</label><input id="Input" type="text"></div>
    <div><label for="ASCII">ASCII</label><input id="ASCII" type="text" readonly="readonly"></div>
    <div><label for="Unicode">Unicode</label><input id="Unicode" type="text" readonly="readonly"></div>
</body>


You can use any tool that supports "Libidn". A quick search showed SimpleDNS might be of help to you.

There are heaps of converters for IDN online, if that's enough for you, you can use one of them.


Internationalized domain name (i.e. domain names with non-ASCII characters) are encoded using the Punycode system.


You encode and decode IDNA with Python:

>>> print u'παιχνιδια'.encode('idna')
xn--mxaaitabzv9d
>>> print 'xn--mxaaitabzv9d'.decode('idna')
παιχνιδια


The standard modules in Perl also in Apache can do it with the URI module.

use URI;
#insert sitename in next:
$sitename = "..";
my $uri = URI->new( $sitename,'http');
if ($uri->scheme) { print $uri; }
0

精彩评论

暂无评论...
验证码 换一张
取 消