= 5.2.0, PHP 7, PHP 8)filter_input — 通過名稱獲取特定的外部變量,并且可以通過過濾器處理它說明filter_input( int $type, string $variable_name, int $fil">

filter_input

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

filter_input通過名稱獲取特定的外部變量,并且可以通過過濾器處理它

說明

filter_input(
    int $type,
    string $variable_name,
    int $filter = FILTER_DEFAULT,
    mixed $options = ?
): mixed

參數(shù)

type

INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVERINPUT_ENV之一。

variable_name

待獲取的變量名。

filter

The 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

一個(gè)選項(xiàng)的關(guān)聯(lián)數(shù)組,或者按位區(qū)分的標(biāo)示。如果過濾器接受選項(xiàng),可以通過數(shù)組的 "flags" 位去提供這些標(biāo)示。

返回值

如果成功的話返回所請(qǐng)求的變量。如果過濾失敗則返回 false ,如果variable_name 不存在的話則返回 null 。 如果標(biāo)示 FILTER_NULL_ON_FAILURE 被使用了,那么當(dāng)變量不存在時(shí)返回 false ,當(dāng)過濾失敗時(shí)返回 null

范例

示例 #1 一個(gè) 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 &#38; son.
<a href='?search=Me%20%26%20son'>Search again.</a>

參見