PHP 中的 filter_var() 函式


filter_var() 函式用於使用指定過濾器篩選變數。

語法

filter_var(variable, filter, options)

引數

  • variable - 變數的名稱。

  • filter - 要獲取 ID 的過濾器的名稱。

  • options - 指定要使用的選項。

返回

filter_var() 函式在成功時返回篩選後的資料,在失敗時返回 false。

示例

線上演示

<?php
   $myEmail = "examplee@demo.com";
   if (filter_var($myEmail, FILTER_VALIDATE_EMAIL {
      echo("$myEmail = valid email address");
   } else {
      echo("$myEmail = invalid email address");
   }
?>

輸出

以下為輸出。

examplee@demo.com = valid email address

更新於: 2019-12-27

396 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.