<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Beaver6813.com &#187; Automatic</title>
	<atom:link href="http://beaver6813.com/tag/automatic/feed/" rel="self" type="application/rss+xml" />
	<link>http://beaver6813.com</link>
	<description>Web Developer Extraordinaire!</description>
	<lastBuildDate>Thu, 05 Jan 2012 20:33:26 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-20304</generator>
		<item>
		<title>[PHP] TLD List, Inc. Level 2 &amp; 3</title>
		<link>http://beaver6813.com/2010/06/php-tld-list-inc-level-2-3/</link>
		<comments>http://beaver6813.com/2010/06/php-tld-list-inc-level-2-3/#comments</comments>
		<pubDate>Sun, 06 Jun 2010 16:48:19 +0000</pubDate>
		<dc:creator>Beaver6813</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[All Level]]></category>
		<category><![CDATA[Automatic]]></category>
		<category><![CDATA[Levels 2 - 3]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[TLD List]]></category>
		<category><![CDATA[Top Level]]></category>
		<category><![CDATA[Updater]]></category>

		<guid isPermaLink="false">http://beaver6813.com/?p=225</guid>
		<description><![CDATA[Whilst working on a new open-source project I needed to be able to be able to detect/remove the TLD&#8217;s from hostnames. This is no easy task algorithmically as example.co.uk (level 2) is just as valid as example.com (level 1) which &#8230; <a href="http://beaver6813.com/2010/06/php-tld-list-inc-level-2-3/">Continue reading <span class="meta-nav">&#8594;</span></a>
Related posts:<ol>
<li><a href='http://beaver6813.com/2009/11/email-to-sms-email-to-mobile-free-database/' rel='bookmark' title='Email to SMS / Email to Mobile, Free Database'>Email to SMS / Email to Mobile, Free Database</a></li>
<li><a href='http://beaver6813.com/2010/04/htc-desire-release-dates/' rel='bookmark' title='HTC Desire Release Dates'>HTC Desire Release Dates</a></li>
<li><a href='http://beaver6813.com/2009/11/multipart-e-mail-code-for-php-text-and-html/' rel='bookmark' title='MultiPart E-Mail Code for PHP (Text and HTML)'>MultiPart E-Mail Code for PHP (Text and HTML)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Whilst working on a new open-source project I needed to be able to be able to detect/remove the TLD&#8217;s from hostnames. This is no easy task algorithmically as example.co.uk (level 2) is just as valid as example.com (level 1) which is also just as valid as example.bob.shiga.jp (level 3). I came across a project from Mozilla that lists all TLDs. This isn&#8217;t the easiest format to work with each time you want to test hostnames. So I&#8217;ve built an auto-updater that will sort and serialize the domains into a format like:<br />
<span id="more-225"></span><br />
[uk] =&gt;</p>
<p style="padding-left: 30px;">*.uk</p>
<p style="padding-left: 30px;">!parliament.uk</p>
<p style="padding-left: 30px;">!nhs.uk</p>
<p>The updater then serializes the array for easy access via PHP at a later date. You may be wondering what the * and !&#8217;s mean. To put it simply it means that there could be anything just before the .uk and it should be counted as the domain such as .co.uk, .gov.uk. The ! before means that its an exception to the * (wildcard) rule, so in the case of parliament.uk, the parliament part should <strong>not</strong> be counted as part of the domain. A full explanation of this can be found at <a href="http://publicsuffix.org/format/" class="broken_link">http://publicsuffix.org/format/</a></p>
<p>Please find below the actual code for the updater. I decided against just posting the serialized list as the list will change over time where as this post may not.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p225code2'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2252"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code" id="p225code2"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//TLD List Updater (Formats to Serialized PHP)</span>
<span style="color: #666666; font-style: italic;">//Created by Beaver6813 (Beaver6813.com). Big thanks to the Mozilla community!</span>
<span style="color: #000088;">$tldlist</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file"><span style="color: #990000;">file</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$toplist</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tldlist</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/trim"><span style="color: #990000;">trim</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/substr_count"><span style="color: #990000;">substr_count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;//&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">&amp;&amp;!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/substr_count"><span style="color: #990000;">substr_count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$sublist</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span>
			<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$dotxplode</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$dotxplode</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_reverse"><span style="color: #990000;">array_reverse</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dotxplode</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$sublist</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$dotxplode</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<a href="http://www.php.net/file_put_contents"><span style="color: #990000;">file_put_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;effective_tld_sublist.dat&quot;</span><span style="color: #339933;">,</span><a href="http://www.php.net/serialize"><span style="color: #990000;">serialize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sublist</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Related posts:<ol>
<li><a href='http://beaver6813.com/2009/11/email-to-sms-email-to-mobile-free-database/' rel='bookmark' title='Email to SMS / Email to Mobile, Free Database'>Email to SMS / Email to Mobile, Free Database</a></li>
<li><a href='http://beaver6813.com/2010/04/htc-desire-release-dates/' rel='bookmark' title='HTC Desire Release Dates'>HTC Desire Release Dates</a></li>
<li><a href='http://beaver6813.com/2009/11/multipart-e-mail-code-for-php-text-and-html/' rel='bookmark' title='MultiPart E-Mail Code for PHP (Text and HTML)'>MultiPart E-Mail Code for PHP (Text and HTML)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://beaver6813.com/2010/06/php-tld-list-inc-level-2-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

