Replace foreign characters

后端 未结 4 1114
时光说笑
时光说笑 2021-01-04 23:59

I need to be able to replace some common foreign characters with English equivalents before I store values into my db.

For example: æ replace with <

4条回答
  •  囚心锁ツ
    2021-01-05 00:42

    For single character of accents

    $str = strtr($str, 
      "ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÝßàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ",
      "AAAAAACEEEEIIIINOOOOOOYSaaaaaaceeeeiiiinoooooouuuuyy"); 
    

    For double character of accents (such as Æ, æ)

    $match   = array('æ', 'Æ');
    $replace = array('ae', 'AE');
    $str = str_replace($replace, $replace, $str);
    

提交回复
热议问题