5 if (file_exists($dbFile)) {
9 $db = new PDO('sqlite:' . dirname(__FILE__) . '/' . $dbFile);
15 description VARCHAR(255)
20 $insert = $db->prepare('
21 INSERT INTO tld (tld, type, description)
22 VALUES (:tld, :type, :description)
25 $contents = file_get_contents(
26 'http://www.iana.org/domains/root/db/'
29 libxml_use_internal_errors(true);
30 $doc = new DOMDocument;
31 $doc->loadHTML($contents);
32 libxml_clear_errors();
34 $descriptions = array(
35 'com' => 'Commercial',
36 'info' => 'Information',
38 'org' => 'Organization',
39 'edu' => 'Educational',
40 'name' => 'Individuals, by name'
43 $xpath = new DOMXPath($doc);
44 $rows = $xpath->query('//tr[contains(@class, "iana-group")]');
45 foreach (range(0, $rows->length - 1) as $index) {
46 $row = $rows->item($index);
47 $tld = strtolower(ltrim($row->childNodes->item(0)->textContent, '.'));
48 $type = $row->childNodes->item(1)->nodeValue;
49 if (isset($descriptions[$tld])) {
50 $description = $descriptions[$tld];
52 $description = $row->childNodes->item(2)->textContent;
53 $regex = '{(^(?:Reserved|Restricted)\s*(?:exclusively\s*)?'
54 . '(?:for|to)\s*(?:members of\s*)?(?:the|support)?'
55 . '\s*|\s*as advised.*$)}i';
56 $description = preg_replace($regex, '', $description);
57 $description = ucfirst(trim($description));
64 'description' => $description
67 $insert->execute($data);