Posted By

martinbrait on 08/12/19


Tagged

delete accents


Versions (?)

[php] supprimer les accents d'une chaîne de caractères


 / Published in: PHP
 

How to delete accents from a string ?

  1. <?php
  2.  
  3.  
  4. function skip_accents( $str, $charset='utf-8' ) {
  5.  
  6. $str = htmlentities( $str, ENT_NOQUOTES, $charset );
  7.  
  8. $str = preg_replace( '#&([A-za-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $str );
  9. $str = preg_replace( '#&([A-za-z]{2})(?:lig);#', '\1', $str );
  10. $str = preg_replace( '#&[^;]+;#', '', $str );
  11.  
  12. return $str;
  13. }
  14.  
  15.  
  16. echo skip_accents("bonjour étienne !");

Report this snippet  

You need to login to post a comment.