php去除非法字符的方法:可以利用php中的str_replace函数来去除字符串中的非法字符,如【$str = str_replace('\\','',$str);】。
本文操作环境:windows10系统、php 7.3、thinkpad t480电脑。
函数介绍:
str_replace() 函数替换字符串中的一些字符(区分大小写)。
语法:
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); $str = str_replace(' ','',$str); return $str; }相关推荐:php教程
以上就是php怎么去除非法字符的详细内容!
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did52765
php怎么去除非法字符
阅读:47次