View Single Post
Old 07-03-2010, 06:42 AM  
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,527
regex for getting domain from url or other methods?

how can I test how fast a regex is compared to others?

I want to be able to get the domain from any url.

Code:
<?php

function get_hostname($url) {
  if (preg_match('#([0-9a-z.-]+)#i',preg_replace('#^(?:(?:\w+):(?:\\?)?)#i','',$url),$matches)) return $matches[1];  
}

$hostname = 'http://www2.example.com:80/test/evil--kj12/cb_2/1.html';
echo $hostname . '<br/> '. get_hostname($hostname);
 
?>
this is what i got so far, works just curious any others got any other ways
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


My Cam Feeds Script / Gallery Scraper / WPXXX Theme / Free Templates
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote