<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Comments on snippet: 'Strip URL to its domain name...'</title>
    <description>Snipplr comments feed</description>
    <link>https://snipplr.com/</link>
    <lastBuildDate>Tue, 14 Apr 2026 12:33:57 +0000</lastBuildDate>
    <item>
      <title>dsntos said on 26/Feb/2009</title>
      <link>https://snipplr.com/view/12616/strip-url-to-its-domain-name</link>
      <description>&lt;p&gt;Or you can use this:&#13;
&#13;
$url= $_SERVER['HTTP_HOST'];&lt;/p&gt;</description>
      <pubDate>Thu, 26 Feb 2009 19:30:11 UTC</pubDate>
      <guid>https://snipplr.com/view/12616/strip-url-to-its-domain-name</guid>
    </item>
    <item>
      <title>xtheonex said on 27/Feb/2009</title>
      <link>https://snipplr.com/view/12616/strip-url-to-its-domain-name</link>
      <description>&lt;p&gt;Omg. How much of a retard do i feel now?! :P&#13;
I Googled for an easy way of doing this and nothing came up so i created my own function, lol.&lt;/p&gt;</description>
      <pubDate>Fri, 27 Feb 2009 02:48:54 UTC</pubDate>
      <guid>https://snipplr.com/view/12616/strip-url-to-its-domain-name</guid>
    </item>
    <item>
      <title>xtheonex said on 27/Feb/2009</title>
      <link>https://snipplr.com/view/12616/strip-url-to-its-domain-name</link>
      <description>&lt;p&gt;Actually. No.&#13;
That will only get the domain name of the host.&#13;
My function, stips down any url passed to it.&#13;
For eg. i used my function to standardize any urls submitted by users.&lt;/p&gt;</description>
      <pubDate>Fri, 27 Feb 2009 02:51:57 UTC</pubDate>
      <guid>https://snipplr.com/view/12616/strip-url-to-its-domain-name</guid>
    </item>
    <item>
      <title>duniyadnd said on 27/Feb/2009</title>
      <link>https://snipplr.com/view/12616/strip-url-to-its-domain-name</link>
      <description>&lt;p&gt;Did you just want to contain the domain's information without the subdomain www? Some site's use www. as a subdomain so you may want to include that. It's a good script, and pretty speedy, here's an alternative if you would prefer:&#13;
&#13;
function stripit ( $url ) {&#13;
        $url = trim($url);&#13;
	$url = preg_replace("/^(http:\/\/)*(www\.)*/is", "", $url);&#13;
	$url = preg_replace("/\/.*$/is" , "" ,$url);&#13;
	return $url;&#13;
}&#13;
&#13;
Created a test for this and yours as well - btw, I just noticed that you have a problem for $url[3]. Don't know if you wanted to keep the sub-directory or not.&#13;
&#13;
$url[0] = " http://www.google.com/test ";&#13;
$url[1] = "http://www.google.com/and";&#13;
$url[2] = "http://web.google.com/bla";&#13;
$url[3] = "http://google.com/go/";&#13;
$url[4] = "www.google.com/jeep";&#13;
$url[5] = "google.com/bam";&#13;
$url[6] = "http://google.com/forget";&#13;
$url[7] = "mail.google.com";&#13;
$url[8] = "google.co.in";&#13;
$url[9] = "http://google.co.uk";&#13;
$url[10] = "http://mail.google.co.uk";&#13;
$url[11] = "google.co.uk/";&#13;
$url[12] = "http://mail.google.co.uk/";&#13;
&#13;
foreach ( $url as $u ) {&#13;
		echo $u."";&#13;
		echo striptodomain($u)."";&#13;
		echo stripit($u)."";&#13;
}&lt;/p&gt;</description>
      <pubDate>Fri, 27 Feb 2009 11:08:55 UTC</pubDate>
      <guid>https://snipplr.com/view/12616/strip-url-to-its-domain-name</guid>
    </item>
  </channel>
</rss>
