Clean Special Characters


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. function just_clean($string)
  4. {
  5. // Replace other special chars
  6. $specialCharacters = array(
  7. '#' => '',
  8. '$' => '',
  9. '%' => '',
  10. '&' => '',
  11. '@' => '',
  12. '.' => '',
  13. '€' => '',
  14. '+' => '',
  15. '=' => '',
  16. '§' => '',
  17. '\\' => '',
  18. '/' => '',
  19. );</code>
  20.  
  21. while (list($character, $replacement) = each($specialCharacters)) {
  22. $string = str_replace($character, '-' . $replacement . '-', $string);
  23. }
  24.  
  25. $string = strtr($string,
  26. "ÀÁÂÃÄÅ� áâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ",
  27. "AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn"
  28. );
  29.  
  30. // Remove all remaining other unknown characters
  31. $string = preg_replace('/[^a-zA-Z0-9\-]/', ' ', $string);
  32. $string = preg_replace('/^[\-]+/', '', $string);
  33. $string = preg_replace('/[\-]+$/', '', $string);
  34. $string = preg_replace('/[\-]{2,}/', ' ', $string);
  35.  
  36. return $string;
  37. }
  38.  
  39.  
  40. ?>

URL: http://www.bala-krishna.com/how-to-clean-special-characters-from-php-string

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.