Posted By

CyrilP on 12/07/18


Tagged

french accent


Versions (?)

Remove accents in a string


 / Published in: PHP
 

URL: https://www.cyrilpenicaud.com

A small function to remove accents in a string.

  1. function accent_cleaner($clean) {
  2. $clean = ereg_replace("[áåâäàã]","a",$clean);
  3. $clean = ereg_replace("ç","c",$clean);
  4. $clean = ereg_replace("[êéèë]","e",$clean);
  5. $clean = ereg_replace("[íîïì]","i",$clean);
  6. $clean = ereg_replace("[óôöòõ]","o",$clean);
  7. $clean = ereg_replace("[ûüùú]","u",$clean);
  8. $clean = ereg_replace("ñ","n",$clean);
  9. $clean = ereg_replace("[ÿý]","y",$clean);
  10.  
  11. $clean = ereg_replace("[ÁÅÂÄÀÃ]","A",$clean);
  12. $clean = ereg_replace("Ç","C",$clean);
  13. $clean = ereg_replace("[ÊÉÈË]","E",$clean);
  14. $clean = ereg_replace("[ÍÎÏÌ]","I",$clean);
  15. $clean = ereg_replace("[ÓÔÖÒÕ]","O",$clean);
  16. $clean = ereg_replace("[ÛÜÙÚ]","U",$clean);
  17. $clean = ereg_replace("Ñ","N",$clean);
  18. $clean = ereg_replace("Ý","Y",$clean);
  19.  
  20. return $clean;
  21. }
  22.  
  23. // Call the function
  24. $string2clean = "Par défaut lorem ipsum ne contient pas d'accent ni de caractères spéciaux contrairement à la langue française qui en contient beaucoup.";
  25. $cleanstring = accent_cleaner($string2clean);
  26. echo $cleanstring;

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: jackhingle on December 7, 2018

Accents in string removed successfully. 192.168.0.1

Posted By: Mccauleyray on December 12, 2018

Thanks, this method worked for me. Router Login

You need to login to post a comment.