我需要删除 0 到 9、a 到 z 或 A 到 Z 之外的任何字符。
这是我的代码:
$alt = preg_replace('/[^0-9a-fA-F]/', '', $_POST['alt-text']);
现在,如果我在其中输入“alt text”,它就会变成“ae”
最佳答案
你有 a-f 而不是 a-z,A-Z 也是如此。
关于regex - 我的正则表达式有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4637210/