PHP 中的 FILTER_VALIDATE_REGEXP 常量

phpprogrammingserver side programming更新于 2025/3/15 13:22:17

FILTER_VALIDATE_REGEXP 常量根据与 Perl 兼容的正则表达式验证值。

选项

  • regexp − 要验证的正则表达式。

返回

FILTER_VALIDATE_REGEXP 常量不返回任何内容。

示例

<?php
   $val="example.com"; 
   $res = array("options"=>array("regexp"=>"/^ex(.*)/"));
   if(filter_var($val, FILTER_VALIDATE_REGEXP,$res)) {
      echo "Matched String!";
   } else {
      echo "Not a Matched String!";
   }
?>

以下是输出。

Matched String!

相关文章