
Untitled
By: a guest on
Jun 9th, 2012 | syntax:
None | size: 0.57 KB | hits: 25 | expires: Never
How can I combine the LOCATE() and SUBSTR() functions in MySQL to create a new column?
id | url
1 | http://www.foo.com/ZedFe.htm
2 | www.foo.com/tEzqz.htm?q=eee
3 | foo.com/ZeeFg.htm
4 | http://www.foo.com/lkeiO
etc.
$id = substr($url, strpos($url,'foo.com/') + 8, 5);
SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(TRIM(LEADING
"https://" FROM TRIM(LEADING "http://" FROM TRIM(url))), "/", 1), ":",
1), ".", IF(url LIKE "%.org.__%" OR url LIKE "%.net.__%" OR url LIKE
"%.com.__%" OR url LIKE "%.__.us%" OR url LIKE "%.co.__%" OR url LIKE
"%.__.uk%", -3, -2) )