替换除字母,数字,空格和下划线以外的所有字符 [英] Replace all characters except letters, numbers, spaces and underscores

查看:395
本文介绍了替换除字母,数字,空格和下划线以外的所有字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望替换字符串中的所有字符,但字母,数字,空格和下划线除外.

I am looking to replace all characters in a string except letters, numbers, spaces and underscores.

有人可以举个例子吗?

推荐答案

我通常使用类似的东西:

I normally use something like:

$string = preg_replace("/[^ \w]+/", "", $string);

这将全部替换所有非空格和非单词字符.

That replaces all non-space and non-word characters with nothing.

这篇关于替换除字母,数字,空格和下划线以外的所有字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆