0

I tried to conver the domain: http://pfeffermühle.com to a correct IDN Domain in Punycode form. I used vb.net and php, but both results are not correct.

VB.net:

Dim idn As New System.Globalization.IdnMapping()
Dim punyCode As String = idn.GetAscii(http://pfeffermühle.com)

RESULT: punyCode= xn--http://pfeffermhle-06b.com

PHP:

echo idn_to_ascii('http://pfeffermühle.com'); 
RESULT: xn--http://pfeffermhle-06b.com

But correct result is: http://xn--pfeffermhle-0hb.com

You can check it here:

http://www.idnconverter.se/http://xn--pfeffermhle-0hb.com

https://www.punycoder.com/

https://www.charset.org/pages/punycode.php?decoded=http%3A%2F%2Fpfefferm%C3%BChle.com&encode=Normal+text+to+Punycode#results

What is the problem?

Please help.

Thanks

memme
  • 112
  • 1
  • 10

1 Answers1

1

Remove the "http://" from the string, its not part of the domainname, it is the used protocoll.

VB.NET

Dim idn As New System.Globalization.IdnMapping()
Dim punyCode As String = idn.GetAscii("pfeffermühle.com")

Console.WriteLine(punyCode)
Console.WriteLine("http://" & idn.GetUnicode(punyCode))

Result:

xn--pfeffermhle-0hb.com
http://pfeffermühle.com

PHP from @memme

$s1 = "hTtps://pfeffermühle.com";;
$s = trim($s1);

if (idn_to_ascii($s) <> $s)
    {
    if (substr(strtolower($s) , 0, 7) === "http://")
        {
        $s = "http://" . idn_to_ascii(substr($s, 7, strlen($s) - 7));
        }
    elseif (substr(strtolower($s) , 0, 8) === "https://")
        {
        $s = "https://" . idn_to_ascii(substr($s, 8, strlen($s) - 8));
        }
    }

echo $s . "<br />" . idn_to_ascii($s1);
David Sdot
  • 2,343
  • 1
  • 20
  • 26
  • 1
    added your php to the answer so it's more complete – David Sdot Jan 18 '17 at 08:57
  • 1
    sorry, correct it would be: $s1="hTtps://pfeffermühle.com"; $s=trim($s1); if (idn_to_ascii($s)<>$s){ if(substr( strtolower($s), 0, 7 ) === "http://"){ $s="http://".idn_to_ascii(substr( $s, 7, strlen($s)-7)); } elseif(substr( strtolower($s), 0, 8 ) === "https://"){ $s="https://".idn_to_ascii(substr( $s, 8, strlen($s)-8)); } } echo $s."
    ".idn_to_ascii($s1);
    – memme Jan 18 '17 at 09:04