prakash Posted June 12, 2007 Share Posted June 12, 2007 I have a collection of URLs, for example: http://story.news.yahoo.com/news/ http://www.amazon.com/exec/obidos/ASIN/B0000C0FKA/ http://www.metafilter.com/mefi/28945 http://www.s-curverecords.com/joss/ http://www.tenaciousd.com/ http://www.pugh.co.uk/ and I need to get only the main domain names from this list, eg: www.yahoo.com www.amazon.com www.metafilter.com www.s-curverecords.com www.tenaciousd.com www.pugh.co.uk what is the code for it. Link to comment https://forums.phpfreaks.com/topic/55288-getting-domain-names-from-a-url/ Share on other sites More sharing options...
trq Posted June 12, 2007 Share Posted June 12, 2007 Take a look at the parse_url() function. Link to comment https://forums.phpfreaks.com/topic/55288-getting-domain-names-from-a-url/#findComment-273304 Share on other sites More sharing options...
prakash Posted June 12, 2007 Author Share Posted June 12, 2007 I got it from the following <?php parse_url($url); $parsed_url=parse_url($url, PHP_URL_HOST); ?> is it correct? Link to comment https://forums.phpfreaks.com/topic/55288-getting-domain-names-from-a-url/#findComment-273452 Share on other sites More sharing options...
TreeNode Posted June 12, 2007 Share Posted June 12, 2007 Looks right, there are other ways of course. Link to comment https://forums.phpfreaks.com/topic/55288-getting-domain-names-from-a-url/#findComment-273461 Share on other sites More sharing options...
legohead6 Posted June 13, 2007 Share Posted June 13, 2007 you could explode() them. Link to comment https://forums.phpfreaks.com/topic/55288-getting-domain-names-from-a-url/#findComment-273590 Share on other sites More sharing options...
neel_basu Posted June 13, 2007 Share Posted June 13, 2007 NOt tested at all ^(?:http://)([^/]+)/(?:.*) Link to comment https://forums.phpfreaks.com/topic/55288-getting-domain-names-from-a-url/#findComment-273714 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.