PHP過濾器 filter_has_var() 函數(shù)用法實(shí)例分析
本文實(shí)例講述了PHP過濾器 filter_has_var() 函數(shù)用法。分享給大家供大家參考,具體如下:
定義和用法filter_has_var() 函數(shù)檢查是否存在指定輸入類型的變量。
如果成功則返回 TRUE,如果失敗則返回 FALSE。
語法filter_has_var(type, variable)
第一個(gè)參數(shù)type(必須):規(guī)定要檢查的類型,可以檢查的類型有INPUT_GET、INPUT_POST、INPUT_COOKIE、INPUT_SERVER、INPUT_ENV 第二個(gè)參數(shù)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
輸出結(jié)果:
Input type exists
使用此函數(shù)可以用來檢查是否是GET或POST提交以及是否有COOKIE變量存在。
當(dāng)然,你也可以使用 isset($_GET['name']) 進(jìn)行判斷
// 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’;
輸出結(jié)果:
NO
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php常用函數(shù)與技巧總結(jié)》、《php字符串(string)用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》及《php程序設(shè)計(jì)算法總結(jié)》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章:
1. 基于android studio的layout的xml文件的創(chuàng)建方式2. 解決Android studio xml界面無法預(yù)覽問題3. 詳解Android studio 動(dòng)態(tài)fragment的用法4. 圖文詳解vue中proto文件的函數(shù)調(diào)用5. 什么是python的自省6. Spring Boot和Thymeleaf整合結(jié)合JPA實(shí)現(xiàn)分頁效果(實(shí)例代碼)7. Android如何加載Base64編碼格式圖片8. 使用Android studio查看Kotlin的字節(jié)碼教程9. Vuex localStorage的具體使用10. Vue封裝一個(gè)TodoList的案例與瀏覽器本地緩存的應(yīng)用實(shí)現(xiàn)

網(wǎng)公網(wǎng)安備