PHP idn_to_ascii/VB.net idn.GetAscii() не приводит к правильному PUNY CODE/IDN домену

Я попытался преобразовать домен: http://pfefferm%C3%BChle.com в правильный домен IDN в форме Punycode. . Я использовал vb.net и php, но оба результата неверны.

ВБ.нет:

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

Но правильный результат: http://xn--pfeffermhle-0hb.com

Вы можете проверить это здесь:

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

В чем проблема?

Пожалуйста помоги.

Спасибо


person memme    schedule 17.01.2017    source источник


Ответы (1)


Удалите "http://" из строки, это не часть имени домена, это используемый протокол.

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))

Результат:

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

PHP от @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);
person David Sdot    schedule 17.01.2017
comment
добавил ваш php в ответ, чтобы он был более полным - person David Sdot; 18.01.2017
comment
извините, правильно будет: $s1=hTtps://pfeffermühle.com; $s=обрезать($s1); if (idn_to_ascii($s)‹›$s){ if(substr(strtolower($s), 0, 7) === http://){ $s=http://.idn_to_ascii(substr( $s , 7, стрлен($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); - person memme; 18.01.2017