= 5.2.0, PHP 7, PHP 8)filter_input — 通過名稱獲取特定的外部變量,并且可以通過過濾器處理它說明filter_input( int $type, string $variable_name, int $fil">
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
filter_input — 通過名稱獲取特定的外部變量,并且可以通過過濾器處理它
type
INPUT_GET, INPUT_POST,
INPUT_COOKIE, INPUT_SERVER或
INPUT_ENV之一。
variable_name待獲取的變量名。
filterThe ID of the filter to apply. The Types of filters manual page lists the available filters.
If omitted, FILTER_DEFAULT will be used, which is
equivalent to
FILTER_UNSAFE_RAW.
This will result in no filtering taking place by default.
options一個選項的關(guān)聯(lián)數(shù)組,或者按位區(qū)分的標(biāo)示。如果過濾器接受選項,可以通過數(shù)組的 "flags" 位去提供這些標(biāo)示。
如果成功的話返回所請求的變量。如果過濾失敗則返回 false ,如果variable_name 不存在的話則返回 null 。
如果標(biāo)示 FILTER_NULL_ON_FAILURE 被使用了,那么當(dāng)變量不存在時返回 false ,當(dāng)過濾失敗時返回 null 。
示例 #1 一個 filter_input() 的例子
<?php
$search_html = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_SPECIAL_CHARS);
$search_url = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_ENCODED);
echo "You have searched for $search_html.\n";
echo "<a href='?search=$search_url'>Search again.</a>";
?>
以上例程的輸出類似于:
You have searched for Me & son. <a href='?search=Me%20%26%20son'>Search again.</a>