Sep 30 2007
How to Get URL Host with MySql?
- REPLACE(url, str2, str1), replace all the "https://" with "http://"
- SUBSTRING_INDEX(xxx, '/', 3), get everything before the 3rd '/'
- REPLACE(yyyy, str1, ''), remove 'http://'
DROP FUNCTION IF EXISTS getHostFromUrl; CREATE FUNCTION getHostFromUrl (url text(1024)) RETURNS CHAR(255) BEGIN DECLARE str1 varchar(10); DECLARE str2 varchar(10); SET str1='http://'; SET str2='https://'; RETURN REPLACE(SUBSTRING_INDEX(REPLACE(url, str2, str1), '/', 3), str1, ''); END;
Soar