如何从文本中删除变音符号? [英] How to remove diacritics from text?
问题描述
我正在建立一个瑞典语网站,瑞典语字母是å,ä和ö.
I am making a swedish website, and swedish letters are å, ä, and ö.
我需要输入用户输入的字符串以使用PHP进行网址安全.
I need to make a string entered by a user to become url-safe with PHP.
基本上,需要将所有字符都转换为下划线,除以下字符外:
Basically, need to convert all characters to underscore, all EXCEPT these:
A-Z, a-z, 1-9
所有瑞典语都应这样转换:
and all swedish should be converted like this:
å"表示"a",ä"表示"a",ö"表示"o"(只需删除上面的点).
'å' to 'a' and 'ä' to 'a' and 'ö' to 'o' (just remove the dots above).
其余的应该像我所说的那样成为下划线.
The rest should become underscores as I said.
我不太擅长使用正则表达式,所以我非常感谢帮助人员!
Im not good at regular expressions so I would appreciate the help guys!
谢谢
注意:不是URLENCODE ...我需要将其存储在数据库中...等等,urlencode对我不起作用.
NOTE: NOT URLENCODE...I need to store it in a database... etc etc, urlencode wont work for me.
推荐答案
// normalize data (remove accent marks) using PHP's *intl* extension
$data = normalizer_normalize($data);
// replace everything NOT in the sets you specified with an underscore
$data = preg_replace("#[^A-Za-z1-9]#","_", $data);
这篇关于如何从文本中删除变音符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!