The League of Extraordinary Packages

Our Packages:

Presented by The League of Extraordinary Packages

Getting Started

The API

The Components

Url is end of life. We strongly encourage you to use League\Uri instead.

The Host class

This class is a segment values component class and manage the URL host component. It implementings the League\Url\Components\HostInterface too.

The interface provides methods to deal with IDN.

HostInterface::toUnicode()

added in version 3.1

This method is an alias of __toString() and return the hostname internationalized name

HostInterface::toAscii()

added in version 3.1

Returns the Punycode encoded hostname;

<?php

use League\Url\Components\Host;

$host = new Host;
$host->set('스타벅스코리아.com'); //you set the IDN
var_export($host->toArray());
//will display
// array(
//    0 => '스타벅스코리아',
//    1 => 'com'
// )
echo $host->toAscii(); // output 'xn--oy2b35ckwhba574atvuzkc.com'
echo $host->toUnicode();  // output '스타벅스코리아.com'

$host->set('xn--mgbh0fb.xn--kgbechtv'); //you set a ascii hostname
echo $host;  // output 'مثال.إختبار'  //the object output the IDN version