Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction of php data filtering method and its related functions

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "the method of php data filtering and the introduction of related functions". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "the method of php data filtering and the introduction of related functions"!

Php data filtering usually uses its own writing method to judge when filtering user input data.

For example, when validating mailboxes, use the regular expression $pattern = "/\ w+ ([- +.']\ w+) * @\ w+ ([-.]\ w+) *\.\ w+ ([-.]\ w+) * /"; if (! preg_match ($pattern, $email)) {throw new\ Exception (self::ERROR_PARAMETER_EMPTY. '_ message format is incorrect:'. $email);}

Is there any other and simple way if you don't use regularization?

Use the filter related function filter_has_var (type, variable) to see if a variable of the specified type exists.

Filter_input takes input from outside the script and filters it.

Filter_input_array takes multiple inputs from outside the script and filters them.

Filter_var takes a variable and filters it.

Filter_var_array takes multiple variables and filters them. Filter_has_var

Determine whether the result of $_ GET contains name

If (! filter_has_var (INPUT_GET, "name")) {echo ("name does not exist");} else {echo ("name exists");} filter_input

Take a look at an example of verifying a mailbox

If (! filter_input (INPUT_GET, 'email', FILTER_VALIDATE_EMAIL)) {echo "E-Mail is not valid";} else {echo "E-Mail is valid";} filter_input_array

Filter the entire input source

$filters = array ("name" = > array ("filter" = > FILTER_CALLBACK, "flags" = > FILTER_FORCE_ARRAY, "options" = > "ucwords"), "age" = > array ("filter" = > FILTER_VALIDATE_INT, "options" = > array ("min_range" = > 1, "max_range" = > 120)) "email" = > FILTER_VALIDATE_EMAIL,) Print_r (filter_input_array (INPUT_POST, $filters)); filter_var,filter_var_array

Do not need input source, filter the value directly

If (! filter_var ("someone@example....com", FILTER_VALIDATE_EMAIL)) {echo ("E-mail is not valid");} else {echo ("E-mail is valid");} scope of the input source

Verification

Other filtering methods strip_tags delete html tags

Htmlentities converts characters into HTML entities, (also escapes currency symbols such as euros, pounds, copyright symbols, etc.)

The htmlspecialchars function converts predefined characters into HTML entities.

The predefined characters are:

& (and sign) becomes &

"(double quotation marks) become"

'(single quotation marks) become'

< (小于)成为 < (大于)成为 >

* hint: to convert a special HTML entity back to characters, use the htmlspecialcharsdecode () function.

$input = "I am the title"; echo htmlspecialchars ($input). "\ n"; echo htmlentities ($input) "\ n"; echo strip_tags ($input) "\ n"; $input = "- 'select * from"; echo addslashes ($input). "\ n"

At this point, I believe you have a deeper understanding of the "introduction of php data filtering methods and related functions". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report