Php 正则表达式很糟糕
如何使这个正则表达式替换空格以及任何非拉丁字母数字字符Php 正则表达式很糟糕,php,regex,Php,Regex,如何使这个正则表达式替换空格以及任何非拉丁字母数字字符 preg_replace('/[^a-zA-Z0-9\s]/', '', $title) 非常感谢[^…]与..不匹配 \s匹配空格 您不希望它与空格不匹配。一切看起来都正常,您只需将其分配给一个变量即可 $title = preg_replace('/[^a-zA-Z0-9\s]/', '', $title) 我只想: <?php preg_match_all('/[a-zA-Z0-9\s]/', $title, $out);
preg_replace('/[^a-zA-Z0-9\s]/', '', $title)
非常感谢
[^…]
与..
不匹配\s
匹配空格
您不希望它与空格不匹配。一切看起来都正常,您只需将其分配给一个变量即可
$title = preg_replace('/[^a-zA-Z0-9\s]/', '', $title)
我只想:
<?php
preg_match_all('/[a-zA-Z0-9\s]/', $title, $out);
$ntitle = implode($out,'');
?>
编辑:不过Briedis是对的,你的正则表达式工作得很好。如果你对正则表达式很糟糕,也许你应该学习它们。你对这个问题的回答帮助我对它们有了更多的了解。谢谢你。哈哈,那可能是个问题(我不想数我做了多少次)。