GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   regex for getting domain from url or other methods? (https://gfy.com/showthread.php?t=976334)

fris 07-03-2010 06:42 AM

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

VideoJ 07-03-2010 06:57 AM

http://php.net/manual/en/function.parse-url.php


All times are GMT -7. The time now is 02:10 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123