php去除非法字符的方法:可以利用php中的str_replace函数来去除字符串中的非法字符,如【$str = str_replace(‘\’,”,$str);】。
本文操作环境:windows10系统、php 7.3、thinkpad t480电脑。
函数介绍:
str_replace() 函数替换字符串中的一些字符(区分大小写)。
语法:
立即学习“PHP免费学习笔记(深入)”;
str_replace(find,replace,string,count)
登录后复制
参数介绍:
find 必需。规定要查找的值。
replace 必需。规定替换 find 中的值的值。
string 必需。规定被搜索的字符串。
count 可选。一个变量,对替换数进行计数。
实现代码:
/** * 去掉字符串里非法的字符 * @param $str string * @return string */function remove_chars($str){ $str = str_replace('\','',$str); $str = str_replace('/','',$str); $str = str_replace('*','',$str); $str = str_replace('?','',$str); $str = str_replace(':','',$str); $str = str_replace('','',$str); $str = str_replace('|','',$str); $str = str_replace('"','',$str); $str = str_replace(' ','',$str); return $str;}
登录后复制
相关推荐:php教程
以上就是php怎么去除非法字符的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2520090.html