替换外来字符 [英] Replace foreign characters

查看:59
本文介绍了替换外来字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这篇关于替换外来字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆