php - Convert "Fancy" unicode ABC to standard ABC
问题描述
I run Regex checks on certain inputs on my site, but the Regex wrongfully returns false when users use "Fancy" Unicode sets such as:
Ⓜⓐⓣⓒⓗ Match ⒨⒜⒯⒞⒣
These are not different fonts, they are different characters! None of these are matched by /Match/
(Proof)
How can I convert the user input to standard ABC characters before running through my Regex checks? (I'm using PHP, if that makes a difference)
解决方案
NFKD unicode规范化应该处理其中的大部分。但是,它似乎只有intl
在启用模块时才有效,而且我的环境中没有它,所以我无法测试它。如果您也没有这样的 PHP,并且不想安装它,这有点类似,至少对于某些字符:
iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text)
最后,您可以制作自己的映射,例如使用strtr
(然后您将知道它可以工作,因为您自己编写了它)。
推荐阅读
- c# - 通过另一个控制器将用户添加到 aspnetuser 表
- c# - 如何在保持程序轻量的同时模拟键盘并同时运行多个命令?
- javascript - 将 processing.js 文件链接到画布
- sql - 基于计算列的值的累积列
- java - 从 Java 中的扫描仪读取多行
- google-apps-script - 如何允许访问写入 Google Drive 电子表格的 Google Web 应用
- sql-server - 停用基于两个分组列的重复数据,检查不为空
- csv - Gephi 上传 csv 文件或在 Gephi 的打开页面选择示例 Les Miserables.gexf 抛出 java.util.MissingResourceException 错误
- c - a 是什么意思?运算符的意思是如果放在变量前面?
- python - ValueError:无法将字符串转换为浮点数:GradientBoostingRegressor 中 .predict 的“错误”