Skip to content

Commit 515c292

Browse files
committed
Adds IDNA info to README
1 parent bafb754 commit 515c292

File tree

1 file changed

+80
-2
lines changed

1 file changed

+80
-2
lines changed

README.md

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ require_once '../vendor/autoload.php';
6565

6666
$pslManager = new Pdp\PublicSuffixListManager();
6767
$parser = new Pdp\Parser($pslManager->getList());
68-
$url = $parser->parseUrl('http://user:[email protected]:8080/path/to/page.html?query=string#fragment');
68+
$host = 'http://user:[email protected]:8080/path/to/page.html?query=string#fragment';
69+
$url = $parser->parseUrl($host);
6970
var_dump($url);
7071
```
7172

@@ -99,13 +100,90 @@ class Pdp\Uri\Url#6 (8) {
99100
}
100101
```
101102

103+
### IDNA Support
104+
105+
#### Unicode
106+
107+
[IDN (Internationalized Domain Name)](http://en.wikipedia.org/wiki/Internationalized_domain_name)
108+
support was added in 1.4.0. Setting `$host = 'Яндекс.РФ';` (Russian-Cyrillic)
109+
in the previous example would return:
110+
111+
```
112+
class Pdp\Uri\Url#6 (8) {
113+
private $scheme =>
114+
string(4) "http"
115+
private $host =>
116+
class Pdp\Uri\Url\Host#5 (4) {
117+
private $subdomain =>
118+
NULL
119+
private $registerableDomain =>
120+
string(17) "яндекс.рф"
121+
private $publicSuffix =>
122+
string(4) "рф"
123+
private $host =>
124+
string(17) "яндекс.рф"
125+
}
126+
private $port =>
127+
NULL
128+
private $user =>
129+
NULL
130+
private $pass =>
131+
NULL
132+
private $path =>
133+
NULL
134+
private $query =>
135+
NULL
136+
private $fragment =>
137+
NULL
138+
}
139+
```
140+
141+
#### ASCII (Punycode)
142+
143+
If you choose to provide the ASCII equivalent of the unicode domain name
144+
(`$host = 'http://xn--d1acpjx3f.xn--p1ai';` in the case of the above example),
145+
the ASCII equivalent will be returned by the parser:
146+
147+
```
148+
class Pdp\Uri\Url#6 (8) {
149+
private $scheme =>
150+
string(4) "http"
151+
private $host =>
152+
class Pdp\Uri\Url\Host#5 (4) {
153+
private $subdomain =>
154+
NULL
155+
private $registerableDomain =>
156+
string(22) "xn--d1acpjx3f.xn--p1ai"
157+
private $publicSuffix =>
158+
string(8) "xn--p1ai"
159+
private $host =>
160+
string(22) "xn--d1acpjx3f.xn--p1ai"
161+
}
162+
private $port =>
163+
NULL
164+
private $user =>
165+
NULL
166+
private $pass =>
167+
NULL
168+
private $path =>
169+
NULL
170+
private $query =>
171+
NULL
172+
private $fragment =>
173+
NULL
174+
}
175+
```
176+
177+
### Convenience Methods
178+
102179
A magic __get() method is provided to access the above object properties. Obtaining the
103180
public suffix for a parsed domain is as simple as:
104181

105182
``` php
106183
<?php
107184

108-
$url = $parser->parseUrl('waxaudio.com.au');
185+
$host = 'waxaudio.com.au';
186+
$url = $parser->parseUrl($host);
109187
$publicSuffix = $url->host->publicSuffix;
110188

111189
// $publicSuffix = 'com.au'

0 commit comments

Comments
 (0)