
Untitled
By: a guest on
Aug 1st, 2012 | syntax:
None | size: 0.71 KB | hits: 9 | expires: Never
How to Extract Domain Name from URL using PHP
<a href='http://google.com.site.com'>google.com</a><br /><a href='http://youtube.com.site.com'>youtube.com</a><br />
preg_match_all ("/a[s]+[^>]*?href[s]?=[s"']+".
"(.*?)["']+.*?>"."([^<]+|.*?)?</a>/",
$var, &$matches);
$matches = $matches[1];
$list = array();
sort($matches);
>(.*?)</a>
<a href=['|"](.*?)?['|"]>
$s = '<a href='http://google.com.site.com'>google.com</a><br /><a href='http://youtube.com.site.com'>youtube.com</a><br /><a href='http://youtube.com.site.com'>extratube.com</a>';
$pattern = '#>(.*?)</a>(<br />)*#';
preg_match_all($pattern, $s, $result);
var_dump($result);
<a[^>]*>(.*?)</a>