替换外来字符

问题描述:

在将值存储到数据库中之前,我需要能够用英语等效项替换一些常见的外来字符.

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

例如:æ替换为 ae ,而ñ替换为 n .

For example: æ replace with ae and ñ with n.

我可以使用preg_replace吗?

Do I use preg_replace?

谢谢

您可以在数组中定义可转换字符,并使用

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);