在php中,如何检查字符串是否根本没有字符。检查一个字符串是否没有字符或数字
目前我喜欢以下,并用' '
替换-
。但是如果一个搜索字符串包含所有不好的单词,它会让我留下' '
(3个空格)。这个长度仍然会显示为3,并且会转到sql处理器。任何方法来检查一个字符串是否没有字符或数字?
$fetch = false;
#$strFromSearchBox = 'Why-you-foo-bar-I-ought-to-tar-you';
$strFromSearchBox = 'foo-bar-tar';
if(strlen($strFromSearchBox) >=2)
{
$newString = str_replace($theseWords,'',$strFromSearchBox);
$newString = str_replace('-',' ',$newString);
if(strlen($newString)>=2)
{
$fetch = true;
echo $newString;
}
}
if($fetch){echo 'True';}else{echo 'False';}
你能解释*“如果搜索字符串包含了所有的坏词” * ......我不明白。你在这之后真的是什么? –
请浏览[PHP的字符串函数首先列表](http://php.net/ref.strings),它可能只包含您正在查找的内容,例如http://php.net/trim – hakre
我的坏话是在一个数组中。 – Norman