Replacing accented characters php

后端 未结 19 1443
鱼传尺愫
鱼传尺愫 2020-11-22 16:03

I am trying to replace accented characters with the normal replacements. Below is what I am currently doing.

    $string = \"Éric Cantona\";
    $strict = st         


        
19条回答
  •  半阙折子戏
    2020-11-22 16:46

    I found this way to be a good one, without having to worry too much about charsets and arrays:

    function replace_accents($str) {
       $str = htmlentities($str, ENT_COMPAT, "UTF-8");
       $str = preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde);/','$1',$str);
       return html_entity_decode($str);
    }
    

提交回复
热议问题