php去除非法字符的方法:可以利用php中的str_replace函数来去除字符串中的非法字符,如【$str = str_replace('\\','',$str);】。

本文操作环境:windows10系统、php 7.3、thinkpad t480电脑。
函数介绍: str_replace() 函数替换字符串中的一些字符(区分大小写)。 语法: str_replace(find,replace,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怎么去除非法字符的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章! |