Last active
May 29, 2018 05:13
-
-
Save michael01angelo/d9f8ce4560c54f3d688ef43aae9c95fc to your computer and use it in GitHub Desktop.
MySQL Convert Normal Text to SEO text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DELIMITER // | |
| CREATE FUNCTION `ToSEO`(input TEXT) | |
| RETURNS TEXT | |
| BEGIN | |
| DECLARE output TEXT DEFAULT ''; | |
| DECLARE iterator INT DEFAULT 1; | |
| WHILE iterator < (LENGTH(input) + 1) DO | |
| IF SUBSTRING(input, iterator, 1) IN (' ', '-') | |
| THEN | |
| SET output = CONCAT(output, '-'); | |
| END IF; | |
| IF SUBSTRING(input, iterator, 1) IN | |
| ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z') | |
| THEN | |
| SET output = CONCAT(output, LCASE(SUBSTRING(input, iterator, 1))); | |
| END IF; | |
| SET iterator = iterator + 1; | |
| END WHILE; | |
| RETURN output; | |
| END // | |
| DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment