我写了这个函数:
function contain_special($string){
# -- Check For Any Special Chars --
if(preg_match('/[^a-z0-9]/',$string)){
# - Special Chars Were Found -
return true;
}//end of special chars found
else{
# - String Does Not Contain Special Chars -
return false;
}//end of else - does not contain special chars
}//end of function
检查字符串是否包含特殊字符。
该函数应该忽略字母数字字符并查找特殊字符。如果找到,返回true
,否则返回false
。
现在,在使用大多数特殊字符进行测试时一切正常:
$text="sdfs-df";
var_dump(contain_special($text));//returns true because "-" was found
但是,当我有一个$
不在字符串的某个位置时,该函数无法拾取它:
$text="sdfsdf$";//this works
$text="sdf$sdf";//this does not work
$text="$sdfsdf";//this works
关于我在这里做错了什么的任何想法?