Php 限制表单验证中的短语

Php 限制表单验证中的短语,php,validation,Php,Validation,我有这个设置来限制人们可以在我的网站上使用什么用户名。是否有任何方法可以让它拾取部分单词,例如捕获单词Administrator?或者管理员或者我管理员 谢谢 $str = "administrator" $os = array("admin", "mellwood"); if (in_array($str, $os)) { $this->form_validation->set_message('username_check', 'Sorry, that

我有这个设置来限制人们可以在我的网站上使用什么用户名。是否有任何方法可以让它拾取部分单词,例如捕获单词Administrator?或者管理员或者我管理员

谢谢

$str = "administrator"
$os = array("admin", "mellwood");

if (in_array($str, $os)) {
            $this->form_validation->set_message('username_check', 'Sorry, that username is not allowed.');
            return FALSE;
    }
只需使用strpos进行如下检查

$str = "administrator"

$os = array("admin", "mellwood");

foreach($os as $name)
{
 if(strpos($name,$str)!==FALSE)
 {
  echo 'you cant use name containing admin';
 }
} 
使用。这将检查用户名是否包含任何限制性条款,无论是哪种情况-例如Admin或Admin或Admin或theAdmin或theAdmin等

$str = 'administrator';

$os = array('admin', 'mellwood');

foreach ($os as $restricted)
    if (stripos($str, $restricted) !== false)
        echo 'username cannot contain the term ' . $restricted;