Php 如何阻止小于3的搜索查询

Php 如何阻止小于3的搜索查询,php,Php,我正在为我的网站做一个搜索功能,但我想阻止少于3个字符的搜索 if($search > 3){ header('Location: error.txt'); } 这可能很简单。请提供帮助您需要使用strlen()获取字符数 if(strlen($search) < 3){ header('Location: error.txt'); } if(strlen($search)

我正在为我的网站做一个搜索功能,但我想阻止少于3个字符的搜索

if($search > 3){
    header('Location: error.txt');
}

这可能很简单。请提供帮助

您需要使用
strlen()
获取字符数

 if(strlen($search) < 3){
   header('Location: error.txt');
}    
if(strlen($search)<3){
标题('Location:error.txt');
}    

您可以在客户端阻止使用jquery。提交前,请检查搜索长度是否小于3,然后不要提交表单。@Gaurav在前端和后端都执行此操作,以确保不仅仅是jquery,而是获取字符串length@Ghost是的,我同意你的看法。我是因为有人已经回答了,所以为什么不写在上面。