Advertisement
Guest User

Untitled

a guest
Jul 5th, 2012
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. /**
  2. * Transliteration (convert foreign and special characters to their ASCII equivalent)
  3. *
  4. * @access public static
  5. * @param string $string The to transliterate.
  6. * @return string The filtered text.
  7. */
  8. function translit($string) {
  9. $search = array(
  10. 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'A', 'A',
  11. 'Ç', 'C', 'C',
  12. 'D', 'Ð',
  13. 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'a', 'a',
  14. 'ç', 'c', 'c',
  15. 'd', 'd',
  16. 'È', 'É', 'Ê', 'Ë', 'E', 'E',
  17. 'G',
  18. 'Ì', 'Í', 'Î', 'Ï', 'I',
  19. 'L', 'L', 'L',
  20. 'è', 'é', 'ê', 'ë', 'e', 'e',
  21. 'g',
  22. 'ì', 'í', 'î', 'ï', 'i',
  23. 'l', 'l', 'l',
  24. 'Ñ', 'N', 'N',
  25. 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'O', 'Œ',
  26. 'R', 'R',
  27. 'S', 'S', 'Š',
  28. 'ñ', 'n', 'n',
  29. 'ò', 'ó', 'ô', 'ö', 'ø', 'o', 'œ',
  30. 'r', 'r',
  31. 's', 's', 'š',
  32. 'T', 'T',
  33. 'Ù', 'Ú', 'Û', 'U', 'Ü', 'U', 'U',
  34. 'Ý', 'ß',
  35. 'Z', 'Z', 'Ž',
  36. 't', 't',
  37. 'ù', 'ú', 'û', 'u', 'ü', 'u', 'u',
  38. 'ý', 'ÿ',
  39. 'z', 'z', 'ž',
  40. '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
  41. '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
  42. '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
  43. '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
  44. '$', '€', '£'
  45. );
  46.  
  47. $replace = array(
  48. 'A', 'A', 'A', 'A', 'A', 'A', 'AE', 'A', 'A',
  49. 'C', 'C', 'C',
  50. 'D', 'D',
  51. 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'a', 'a',
  52. 'c', 'c', 'c',
  53. 'd', 'd',
  54. 'E', 'E', 'E', 'E', 'E', 'E',
  55. 'G',
  56. 'I', 'I', 'I', 'I', 'I',
  57. 'L', 'L', 'L',
  58. 'e', 'e', 'e', 'e', 'e', 'e',
  59. 'g',
  60. 'i', 'i', 'i', 'i', 'i',
  61. 'l', 'l', 'l',
  62. 'N', 'N', 'N',
  63. 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'OE',
  64. 'R', 'R',
  65. 'S', 'S', 'S',
  66. 'n', 'n', 'n',
  67. 'o', 'o', 'o', 'o', 'o', 'o', 'oe',
  68. 'r', 'r',
  69. 's', 's', 's',
  70. 'T', 'T',
  71. 'U', 'U', 'U', 'U', 'U', 'U', 'U',
  72. 'Y', 'Y',
  73. 'Z', 'Z', 'Z',
  74. 't', 't',
  75. 'u', 'u', 'u', 'u', 'u', 'u', 'u',
  76. 'y', 'y',
  77. 'z', 'z', 'z',
  78. 'A', 'B', 'B', 'r', 'A', 'E', 'E', 'X', '3', 'N', 'N', 'K', 'N', 'M', 'H', 'O', 'N', 'P',
  79. 'a', 'b', 'b', 'r', 'a', 'e', 'e', 'x', '3', 'n', 'n', 'k', 'n', 'm', 'h', 'o', 'p',
  80. 'C', 'T', 'Y', 'O', 'X', 'U', 'u', 'W', 'W', 'b', 'b', 'b', 'E', 'O', 'R',
  81. 'c', 't', 'y', 'o', 'x', 'u', 'u', 'w', 'w', 'b', 'b', 'b', 'e', 'o', 'r',
  82. 'USD', 'EUR', 'GBP'
  83. );
  84.  
  85. return str_replace($search, $replace, $string);
  86. }
  87.  
  88. /**
  89. * Rewrite a text to its URL compatible equivalent.
  90. *
  91. * @access public static
  92. * @param string $string The text to convert.
  93. * @return string The converted URL.
  94. */
  95. function slugify($string, $charset = 'UTF-8') {
  96. $string = htmlspecialchars_decode($string); // ie: & to &
  97. $string = translit($string); // ie: é to e
  98. $string = preg_replace('/[^A-Za-z0-9]+/', '-', $string); // ie: _ to -
  99. $string = trim($string, '-'); // ie: -string- to string
  100. $string = mb_strtolower($string); // ie: E to e
  101.  
  102. return $string;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement