-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.php
67 lines (63 loc) · 2.51 KB
/
demo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/***************************************************************************//**
* This file contains some example code to demonstrate the features of the lib.
******************************************************************************/
/***************************************************************************//**
* Short intro: This lib was built to be used as a simple URL-parts splitter.
* You provide a URL, and it will return the sub domains, registrable domain,
* and the public suffix seperately. Example:
* Example URL: http://shop.retailer.mystore.co.uk
* will return:
* [0] = shop.retailer (sub domains)
* [1] = mystore (registrable domain)
* [2] = co.uk (public suffix).
*
* The data comes from https://github.com/publicsuffix/list which is updated
* regularly and if you decide to use it you should update the .dat file stored
* in /publicsuffixlists/ from time to time. The lib parses only public ICANN
* domains, and not private ones, however you can fork and adapt the code as
* as you see fit.
*
* The lib actually uses a pre-generated PHP array instead of the .dat file for
* performance reasons (no pre-processing required, and no external data loads).
*
* Every time you update the .dat file, you should also run
* /src/serializeToPHP.php to update the PHP array as well.
*
* Finally this simplified parser was inspired by:
* - https://github.com/jeremykendall/php-domain-parser
* - https://github.com/peerigon/parse-domain
******************************************************************************/
require_once './index.php';
$urls = array(
'com',
'example.COM',
'WwW.example.COM',
'.com',
'.example',
'example.uk.com',
'test.jp',
'www.test.jp',
'www.test.k12.ak.us',
'shop.retail.mystore.co.uk',
'test.test.at',
'buynow.com.br',
'食狮.中国',
'xn--85x722f.com.cn',
'www.食狮.公司.cn',
'http://username:password@firstexample.com/',
'http://username:password@regdomain.com:9090/path?arg=value#anchor',
'mailto:someone@example.com',
'mailto:someone@example.com?subject=This%20is%20the%20subject'.//cont...
'&cc=someone_else@example.com&body=This%20is%20the%20body',
'mailto:someone@example.com,someoneelse@example.com', // parses just one here
'anotherone@example.com',
'mytest.com?myquery',
'welovearuba.com.aw/subfolder1/subfolder2',
);
foreach ($urls as $url) {
echo 'URL: '.$url;
echo '<pre>';
echo var_dump(\simplePHPDomainParser\getDomain($url));
echo '</pre><br />---<br />';
}