<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: PHP &#8211; How to get domain name from URL?</title>
	<atom:link href="http://corpocrat.com/2009/02/28/php-how-to-get-domain-hostname-from-url/feed/" rel="self" type="application/rss+xml" />
	<link>http://corpocrat.com/2009/02/28/php-how-to-get-domain-hostname-from-url/</link>
	<description>Daily Blog from Internet Entrepreneur/Webmaster</description>
	<lastBuildDate>Thu, 09 Sep 2010 16:51:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Freelance PHP Programmer</title>
		<link>http://corpocrat.com/2009/02/28/php-how-to-get-domain-hostname-from-url/#comment-7710</link>
		<dc:creator>Freelance PHP Programmer</dc:creator>
		<pubDate>Sun, 18 Jul 2010 08:55:08 +0000</pubDate>
		<guid isPermaLink="false">http://corpocrat.com/2009/02/28/php-how-to-get-domain-hostname-from-url/#comment-7710</guid>
		<description>This domain extract function helped me for my academic project. Thanx.</description>
		<content:encoded><![CDATA[<p>This domain extract function helped me for my academic project. Thanx.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Madeline Morgan</title>
		<link>http://corpocrat.com/2009/02/28/php-how-to-get-domain-hostname-from-url/#comment-7547</link>
		<dc:creator>Madeline Morgan</dc:creator>
		<pubDate>Wed, 19 May 2010 08:33:56 +0000</pubDate>
		<guid isPermaLink="false">http://corpocrat.com/2009/02/28/php-how-to-get-domain-hostname-from-url/#comment-7547</guid>
		<description>What company is the best Domain Registrar? i&#039;ve heard that Godaddy and Moniker are the best.:`:</description>
		<content:encoded><![CDATA[<p>What company is the best Domain Registrar? i&#8217;ve heard that Godaddy and Moniker are the best.:`:</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: IDENTA</title>
		<link>http://corpocrat.com/2009/02/28/php-how-to-get-domain-hostname-from-url/#comment-7488</link>
		<dc:creator>IDENTA</dc:creator>
		<pubDate>Wed, 28 Apr 2010 06:01:14 +0000</pubDate>
		<guid isPermaLink="false">http://corpocrat.com/2009/02/28/php-how-to-get-domain-hostname-from-url/#comment-7488</guid>
		<description>The below function worked very well:

function getDomain($url)
{
    if(filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) === FALSE)
    {
        return false;
    }
    /*** get the url parts ***/
    $parts = parse_url($url);
    /*** return the host domain ***/
    return $parts[&#039;scheme&#039;].&#039;://&#039;.$parts[&#039;host&#039;];
}</description>
		<content:encoded><![CDATA[<p>The below function worked very well:</p>
<p>function getDomain($url)<br />
{<br />
    if(filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) === FALSE)<br />
    {<br />
        return false;<br />
    }<br />
    /*** get the url parts ***/<br />
    $parts = parse_url($url);<br />
    /*** return the host domain ***/<br />
    return $parts['scheme'].&#8217;://&#8217;.$parts['host'];<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: yudi</title>
		<link>http://corpocrat.com/2009/02/28/php-how-to-get-domain-hostname-from-url/#comment-4202</link>
		<dc:creator>yudi</dc:creator>
		<pubDate>Tue, 23 Jun 2009 18:13:18 +0000</pubDate>
		<guid isPermaLink="false">http://corpocrat.com/2009/02/28/php-how-to-get-domain-hostname-from-url/#comment-4202</guid>
		<description>// get host name from URL
preg_match(&#039;@^(?:http://)?([^/]+)@i&#039;,
    &quot;http://www.php.net/index.html&quot;, $matches);
$host = $matches[1];

// get last two segments of host name
preg_match(&#039;/[^.]+\.[^.]+$/&#039;, $host, $matches);
echo &quot;domain name is: {$matches[0]}\n&quot;;</description>
		<content:encoded><![CDATA[<p>// get host name from URL<br />
preg_match(&#8216;@^(?:http://)?([^/]+)@i&#8217;,<br />
    &#8220;http://www.php.net/index.html&#8221;, $matches);<br />
$host = $matches[1];</p>
<p>// get last two segments of host name<br />
preg_match(&#8216;/[^.]+\.[^.]+$/&#8217;, $host, $matches);<br />
echo &#8220;domain name is: {$matches[0]}\n&#8221;;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: yudi</title>
		<link>http://corpocrat.com/2009/02/28/php-how-to-get-domain-hostname-from-url/#comment-4201</link>
		<dc:creator>yudi</dc:creator>
		<pubDate>Tue, 23 Jun 2009 18:12:41 +0000</pubDate>
		<guid isPermaLink="false">http://corpocrat.com/2009/02/28/php-how-to-get-domain-hostname-from-url/#comment-4201</guid>
		<description>The right one

</description>
		<content:encoded><![CDATA[<p>The right one</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Austin</title>
		<link>http://corpocrat.com/2009/02/28/php-how-to-get-domain-hostname-from-url/#comment-3079</link>
		<dc:creator>Austin</dc:creator>
		<pubDate>Thu, 05 Mar 2009 20:19:47 +0000</pubDate>
		<guid isPermaLink="false">http://corpocrat.com/2009/02/28/php-how-to-get-domain-hostname-from-url/#comment-3079</guid>
		<description>&lt;code&gt;function getDomain( $inputURL ) {
	
	$arrayURL = explode( &#039;.&#039;, $inputURL );
	$i = count( $arrayURL ) - 1;
	
	if( strlen( $arrayURL[ $i ] ) &lt;= 2 &amp;&amp; strlen( $arrayURL[ $i - 1 ] ) &amp;lt= 2 ) {
		
		$cleanURL = $arrayURL[ $i - 2 ] . &#039;.&#039; .$arrayURL[ $i - 1 ] . &#039;.&#039; . $arrayURL[ $i ];
		
		
	} else {
		
		$cleanURL = $arrayURL[ $i - 1 ] . &#039;.&#039; . $arrayURL[ $i ];
		
	}
	
	return $cleanURL;
	
}&lt;/code&gt;

Correction on the code.</description>
		<content:encoded><![CDATA[<p><code>function getDomain( $inputURL ) {</p>
<p>	$arrayURL = explode( '.', $inputURL );<br />
	$i = count( $arrayURL ) - 1;</p>
<p>	if( strlen( $arrayURL[ $i ] ) &lt;= 2 &amp;&amp; strlen( $arrayURL[ $i - 1 ] ) &amp;lt= 2 ) {</p>
<p>		$cleanURL = $arrayURL[ $i - 2 ] . '.' .$arrayURL[ $i - 1 ] . '.' . $arrayURL[ $i ];</p>
<p>	} else {</p>
<p>		$cleanURL = $arrayURL[ $i - 1 ] . '.' . $arrayURL[ $i ];</p>
<p>	}</p>
<p>	return $cleanURL;</p>
<p>}</code></p>
<p>Correction on the code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Austin</title>
		<link>http://corpocrat.com/2009/02/28/php-how-to-get-domain-hostname-from-url/#comment-3078</link>
		<dc:creator>Austin</dc:creator>
		<pubDate>Thu, 05 Mar 2009 20:18:59 +0000</pubDate>
		<guid isPermaLink="false">http://corpocrat.com/2009/02/28/php-how-to-get-domain-hostname-from-url/#comment-3078</guid>
		<description>Sorry, but neither of these functions really work.

On the first:
You can have subdomains that aren&#039;t &#039;www&#039;. If I put in &#039;http://sub.gulati.info&#039;, I would expect the return of &#039;gulati.info&#039;, but your function gives me &#039;sub.gulati.info&#039;.

Here&#039;s a better function:

&lt;code&gt;function getDomain( $inputURL ) {
	
	$arrayURL = explode( &#039;.&#039;, $inputURL );
	$i = count( $arrayURL ) - 1;
	
	if( strlen( $arrayURL[ $i ] ) 

This will work for everything except CC.CC urls (such as ab.us or something).

On the second:

It gives me a couple of regex errors.

Thanks!</description>
		<content:encoded><![CDATA[<p>Sorry, but neither of these functions really work.</p>
<p>On the first:<br />
You can have subdomains that aren&#8217;t &#8216;www&#8217;. If I put in &#8216;http://sub.gulati.info&#8217;, I would expect the return of &#8216;gulati.info&#8217;, but your function gives me &#8216;sub.gulati.info&#8217;.</p>
<p>Here&#8217;s a better function:</p>
<p><code>function getDomain( $inputURL ) {</p>
<p>	$arrayURL = explode( '.', $inputURL );<br />
	$i = count( $arrayURL ) - 1;</p>
<p>	if( strlen( $arrayURL[ $i ] ) </p>
<p>This will work for everything except CC.CC urls (such as ab.us or something).</p>
<p>On the second:</p>
<p>It gives me a couple of regex errors.</p>
<p>Thanks!</code></p>
]]></content:encoded>
	</item>
</channel>
</rss>
