删除空格和任何非字母数字的内容 [英] Removing spaces and anything that is not alphanumeric

查看:43
本文介绍了删除空格和任何非字母数字的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除所有非字母数字或带有 _ 的空格:

I'm trying to remove everything that is not alphanumeric, or is a space with _:

$filename = preg_replace("([^a-zA-Z0-9]|^\s)", "_", $filename);

我在这里做错了什么,它似乎不起作用.我尝试了几种正则表达式组合......(而且我通常不是很聪明).

What am I doing wrong here, it doesn't seem to work. I've tried several regex combinations...(and I'm generally not very bright).

推荐答案

试试这个:

$filename = preg_replace("/[^a-zA-Z0-9 ]/", "_", $filename);

这篇关于删除空格和任何非字母数字的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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