PHP filter_input()関数
例
外部変数「email」が「get」メソッドを介してPHPページに送信されているかどうかを確認し、それが有効な電子メールアドレスであるかどうかも確認します。
<?php
if (!filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL)) {
echo("Email is not valid");
} else {
echo("Email is valid");
}
?>
定義と使用法
filter_input()関数は、外部変数(たとえば、フォーム入力から)を取得し、オプションでそれをフィルター処理します。
この関数は、ユーザー入力などの安全でないソースからの変数を検証するために使用されます。
構文
filter_input(type, variable, filter, options)
パラメータ値
Parameter | Description |
---|---|
type | Required. The input type to check for. Can be one of the following:
|
variable | Required. The variable name to check |
filter | Optional. Specifies the ID or name of the filter to use. Default is FILTER_DEFAULT, which results in no filtering |
options | Optional. Specifies one or more flags/options to use. Check each filter for possible options and flags |
技術的な詳細
戻り値: | 成功した場合は変数の値、失敗した場合はFALSE、変数が設定されていない場合はNULL |
---|---|
PHPバージョン: | 5.2+ |
❮完全なPHPフィルターリファレンス