使用preg_match "script"在cakephp 1.3控制器中验证字符串


validating string in cakephp 1.3 controller with preg_match "script"

我如何找到如果字符串包含"script"标记preg_match,…?我试图避免/上船提交,如果数据传递为"脚本"

 $short_status = $this->params['form']['value'];
 $regex = '/^[<script>]$/i'; 
 if(preg_match($regex, $short_status))
 {
 die();
 }
 else
 {
 to process post and save to database,... 

提前感谢,克里斯。

使用以下正则表达式:#</?script[^>]*>#i .

测试:

if(preg_match('#</?script[^>]*>#i', '<script type="text/javascript">')){
    echo 'SCRIPT FOUND';
}else{
    echo 'Baah, nothing';
}

毕竟……以下是对我有用的:

   $short_status = $this->params['form']['value'];
   $regex = '/^<'w+|script|java|javascript|>$/';
       if(preg_match($regex, $short_status))
      {
    die(); // aboard submission
      }
else
{
     // go to submission and save 

享受它,……