[英]php str_replace for danish char's
I am removing danish special char's from a string, I have a string like this 1554896020A2å.pdf danish char's are "æ ø å " for removing danish char's I am using str_replace , I successfully remove these two "æ ø" char's but I don't know this one "å" is not removed from the string.我正在从字符串中删除丹麦特殊字符,我有一个像这样的字符串1554896020A2å.pdf丹麦字符是“æ ø å”用于删除丹麦字符我正在使用str_replace ,我成功地删除了这两个“æ ø”字符,但我没有不知道这个“å”没有从字符串中删除。 thanks for your help in advance.提前感谢您的帮助。
I have used this to remove danish char's我用它来删除丹麦字符
$patterns = array('å', 'æ', 'ø');
$replacements = array('/x7D', 'X', '/x7C');
echo str_replace($patterns, $replacements, 1554896020A2å.pdf);
The a
you have in the string is not a single code unit, it is a code point consisting of two code units, \\xCC
and \\x8A
.在a
你的字符串中有不是一个单一的代码单元,它是由两个代码单元,代码点\\xCC
和\\x8A
。
Thus, you may add this value to your patterns/replacements:因此,您可以将此值添加到您的模式/替换中:
$patterns = array('å', "a\xCC\x8A", "A\xCC\x8A", 'Å', 'æ', 'ø');
$replacements = array('/x7D', '/x7D', '/x7D', '/x7D', 'X', '/x7C');
echo str_replace($patterns, $replacements, '1554896020A2å.pdf');
// => 1554896020A2/x7D.pdf
In PHP 7, you may use "a\\u{030A}"
/ "A\\u{030A}"
to match these a
letters with their diacritic symbol.在 PHP 7 中,您可以使用"a\\u{030A}"
/ "A\\u{030A}"
将这些a
字母与其变音符号匹配。
Note that you may use /a\\p{M}+/ui
regex pattern with preg_replace
if you decide to go with regex and match any a
s followed with diacritic marks.请注意,如果您决定使用正则表达式并匹配任何带有变音符号的a
s,则可以将/a\\p{M}+/ui
正则表达式模式与preg_replace
一起使用。 i
is for case insensitive matching, remove if not needed. i
用于不区分大小写的匹配,如果不需要,请删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.