$html = 'some text here<a href="http://www.mydomain.com/page.html">URL</a> some text here as well'; $url = preg_match('/<a href="(.+)">/', $html, $match); $info = parse_url($match[1]); echo $info['scheme'].'://'.$info['host'];