/ Published in: PHP
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.
[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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<? $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 ) { return $url; } ?>