PHP过滤器 filter_has_var() 函数

定义和用法

filter_has_var() 函数检查是否存在指定输入类型的变量。

如果成功则返回 TRUE,如果失败则返回 FALSE。

语法

filter_has_var(type, variable)
第一个参数type(必须):规定要检查的类型,可以检查的类型有INPUT_GET、INPUT_POST、INPUT_COOKIE、INPUT_SERVER、INPUT_ENV
第二个参数variable(必须):需要检查的变量
 
例子:
<?php
    if(!filter_has_var(INPUT_GET, "name")) {
        echo("Input type does not exist");
    }
    else {
        echo("Input type exists");
    }

地址栏输入链接:localhost://test.php?name=test

输出结果:
Input type exists

使用此函数可以用来检查是否是GET或POST提交以及是否有COOKIE变量存在。

当然,你也可以使用 isset($_GET["name"]) 进行判断

 

    // Please note that the function does not check the live array, 
    // it actually checks the content received by php:
    $_GET['name'] = 1;
    echo filter_input(INPUT_GET, 'name') ? 'Yes' : 'No';

输出结果:

NO

 

posted @ 2018-04-08 00:25  Ryan_zheng  阅读(607)  评论(0编辑  收藏  举报