My db table has a column called url which contains data like: http://xyz.com/cat/index/?page=2 http://www.google.com/webmaster.php http://yahoo.com/dsdsd/category.aspx etc. I want to just fetch their domain names like: xyz.com google.com yahoo.com How should I write the query in mysql to get the above result. Please help.
If you want to do it through MYSQL SELECT SUBSTRING_INDEX(REPLACE(REPLACE(url, "http://", ""), "www.", ""), '/', 1); Code (markup): If you want to do it through PHP $parsed = parse_url($url); $domain = $parsed['hostname']; PHP: