Replace foreign characters

后端 未结 4 1148
时光说笑
时光说笑 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:43

    You can define your convertable characters in an array, and use str_replace():

    $conversions = array(
        "æ" => "ae",
        "ñ" => "n",
    );
    
    $text = str_replace(array_keys($conversions), $conversions, $text);
    

提交回复
热议问题