gpt4 book ai didi

php - 如何替换所有特殊字符但保留重音符号

转载 作者:行者123 更新时间:2023-12-02 21:36:55 24 4
gpt4 key购买 nike

我想更改字符串中的所有特殊字符,但我想保留所有重音字符。是否可以使用 preg_replace()

我当前的代码:

preg_replace('/[^A-Za-z0-9\-]/', '', $string); 

最佳答案

尝试使用 Unicode:

preg_replace('/[^\p{L}0-9\-]/u', '', $string);

\p{L}Unicode property匹配任何语言的所有字母,Unicode properties on php.net

关于php - 如何替换所有特殊字符但保留重音符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21160769/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com