What is the usage of filter_input in php

WBOY
Release: 2023-03-15 12:16:01
Original
2169 people have browsed it

In PHP, the "filter_input()" function is used to verify variables from non-safe sources, obtain input from outside the script, and filter it. If successful, the filtered data will be returned, and if it fails, false will be returned. , the syntax is "filter_input(input type, filtered variable, filter ID, array)".

What is the usage of filter_input in php

The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.

What is the usage of filter_input in php

The filter_input() function gets input from outside the script and filters it.

This function is used to verify variables from non-safe sources, such as user input.

This function can get input from various sources:

  • INPUT_GET

  • INPUT_POST

  • INPUT_COOKIE

  • INPUT_ENV

  • INPUT_SERVER

  • ##INPUT_SESSION (Not yet implemented)

  • INPUT_REQUEST (Not yet implemented)

If successful, return the filtered data, if failed, return false, if the variable parameter is not If set, NULL is returned.

Syntax

filter_input(input_type, variable, filter, options)
Copy after login

input_type Required. Specifies the input type. See the list of possible types above.

variable specifies the variable to filter.

filter is optional. Specifies the ID of the filter to use. The default is FILTER_SANITIZE_STRING.

options Specifies an array containing flags/options. Check the possible flags and options for each filter.

The example is as follows:

In this example, we use the filter_input() function to filter a POST variable. Accepted POST variables are valid e-mail addresses.

<?php
if (!filter_input(INPUT_POST, &#39;email&#39;, FILTER_VALIDATE_EMAIL))
 {
 echo "E-Mail is not valid";
 }
else
 {
 echo "E-Mail is valid";
 }
?>
Copy after login

Output is similar:

E-Mail is valid

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of What is the usage of filter_input in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!