Revision: 12109
Updated Code
at March 3, 2009 09:49 by duniyadnd
Updated Code
<? $url[0] = " http://www.google.com/test "; $url[1] = "http://www.google.com/and"; $url[2] = "http://web.google.com/bla"; $url[3] = "http://google.com/go/"; $url[4] = "www.google.com/jeep"; $url[5] = "google.com/bam"; $url[6] = "http://google.com/forget"; $url[7] = "mail.google.com"; $url[8] = "google.co.in"; $url[9] = "http://google.co.uk"; $url[10] = "http://mail.google.co.uk"; $url[11] = "google.co.uk/"; $url[12] = "http://mail.google.co.uk/"; foreach ( $url as $u ) { echo stripit($u)."<br>"; } /*** this is the stripit function for you copy/pasters out there ***/ function stripit ( $url ) { $url = trim($url); $url = preg_replace("/^(http:\/\/)*(www.)*/is", "", $url); $url = preg_replace("/\/.*$/is" , "" ,$url); return $url; } ?>
Revision: 12108
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 2, 2009 16:44 by duniyadnd
Initial Code
function stripit ( $url ) { $url = trim($url); $url = pregreplace("/^(http:\/\/)*(www.)*/is", "", $url); $url = pregreplace("/\/.*$/is" , "" ,$url); return $url; }
Initial URL
Initial Description
Alternative to [http://snipplr.com/view/12616/strip-url-to-its-domain-name/](http://snipplr.com/view/12616/strip-url-to-its-domain-name/, "this snippet"), as it didn't come out clearly in the comments. Update - Edited based on gdvickery's comment - thanks! Also added a test case so people can see how it works.
Initial Title
Strip URL to domain name
Initial Tags
url
Initial Language
PHP