You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unicode字符转ASCII普通字符的PHP处理问题求助

Unicode字符转ASCII普通字符的PHP处理问题求助

我看了好多讲解如何处理Unicode字符的帖子,但所有建议对我都不管用,真的卡壳了!

我的PHP页面会读取一个包含高阶字符的文件,比如字符串Mötor,我想把这类字符串转换成“普通”字符,也就是变成Motor。

下面是我试过的所有方法,结果都不尽如人意:

  • 尝试1:
$source = "Mötor";
$test = preg_replace('/[^\w\d\p{L}]/u', "", $source); // 返回 null
  • 尝试2:
$test = preg_replace('/[^\w\d\p{L}]/u', "", htmlentities($source)); // 返回 ""
  • 尝试3:
$test = preg_replace("/&([a-z])[a-z]+;/i", "$1", $source); // 返回 "Mötor"
  • 尝试4:
$test = preg_replace("/&([a-z])[a-z]+;/i", "$1", htmlentities($source)); // 返回 ""
  • 尝试5:
$test = iconv('utf-8', 'ascii//TRANSLIT', $source); // 返回 false

我实在没辙了,求大家帮忙!

备注:内容来源于stack exchange,提问作者Steve A

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 09:18:01