Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Transliteration (convert foreign and special characters to their ASCII equivalent)
- *
- * @access public static
- * @param string $string The to transliterate.
- * @return string The filtered text.
- */
- function translit($string) {
- $search = array(
- 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'A', 'A',
- 'Ç', 'C', 'C',
- 'D', 'Ð',
- 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'a', 'a',
- 'ç', 'c', 'c',
- 'd', 'd',
- 'È', 'É', 'Ê', 'Ë', 'E', 'E',
- 'G',
- 'Ì', 'Í', 'Î', 'Ï', 'I',
- 'L', 'L', 'L',
- 'è', 'é', 'ê', 'ë', 'e', 'e',
- 'g',
- 'ì', 'í', 'î', 'ï', 'i',
- 'l', 'l', 'l',
- 'Ñ', 'N', 'N',
- 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'O', 'Œ',
- 'R', 'R',
- 'S', 'S', 'Š',
- 'ñ', 'n', 'n',
- 'ò', 'ó', 'ô', 'ö', 'ø', 'o', 'œ',
- 'r', 'r',
- 's', 's', 'š',
- 'T', 'T',
- 'Ù', 'Ú', 'Û', 'U', 'Ü', 'U', 'U',
- 'Ý', 'ß',
- 'Z', 'Z', 'Ž',
- 't', 't',
- 'ù', 'ú', 'û', 'u', 'ü', 'u', 'u',
- 'ý', 'ÿ',
- 'z', 'z', 'ž',
- '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
- '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
- '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
- '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
- '$', '€', '£'
- );
- $replace = array(
- 'A', 'A', 'A', 'A', 'A', 'A', 'AE', 'A', 'A',
- 'C', 'C', 'C',
- 'D', 'D',
- 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'a', 'a',
- 'c', 'c', 'c',
- 'd', 'd',
- 'E', 'E', 'E', 'E', 'E', 'E',
- 'G',
- 'I', 'I', 'I', 'I', 'I',
- 'L', 'L', 'L',
- 'e', 'e', 'e', 'e', 'e', 'e',
- 'g',
- 'i', 'i', 'i', 'i', 'i',
- 'l', 'l', 'l',
- 'N', 'N', 'N',
- 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'OE',
- 'R', 'R',
- 'S', 'S', 'S',
- 'n', 'n', 'n',
- 'o', 'o', 'o', 'o', 'o', 'o', 'oe',
- 'r', 'r',
- 's', 's', 's',
- 'T', 'T',
- 'U', 'U', 'U', 'U', 'U', 'U', 'U',
- 'Y', 'Y',
- 'Z', 'Z', 'Z',
- 't', 't',
- 'u', 'u', 'u', 'u', 'u', 'u', 'u',
- 'y', 'y',
- 'z', 'z', 'z',
- 'A', 'B', 'B', 'r', 'A', 'E', 'E', 'X', '3', 'N', 'N', 'K', 'N', 'M', 'H', 'O', 'N', 'P',
- 'a', 'b', 'b', 'r', 'a', 'e', 'e', 'x', '3', 'n', 'n', 'k', 'n', 'm', 'h', 'o', 'p',
- 'C', 'T', 'Y', 'O', 'X', 'U', 'u', 'W', 'W', 'b', 'b', 'b', 'E', 'O', 'R',
- 'c', 't', 'y', 'o', 'x', 'u', 'u', 'w', 'w', 'b', 'b', 'b', 'e', 'o', 'r',
- 'USD', 'EUR', 'GBP'
- );
- return str_replace($search, $replace, $string);
- }
- /**
- * Rewrite a text to its URL compatible equivalent.
- *
- * @access public static
- * @param string $string The text to convert.
- * @return string The converted URL.
- */
- function slugify($string, $charset = 'UTF-8') {
- $string = htmlspecialchars_decode($string); // ie: & to &
- $string = translit($string); // ie: é to e
- $string = preg_replace('/[^A-Za-z0-9]+/', '-', $string); // ie: _ to -
- $string = trim($string, '-'); // ie: -string- to string
- $string = mb_strtolower($string); // ie: E to e
- return $string;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement