Home>Article>Daily Programming> How to filter spaces in post submission data in PHP

How to filter spaces in post submission data in PHP

藏色散人
藏色散人 Original
2018-10-24 11:13:04 8984browse

This article mainly introduces how PHP filters the data submitted by post with spaces.

Everyone should know that when we develop the login interface, in addition to some js verification at the front end, there are also some verifications after submitting data to the backend.

So about the front-end verification method for form submission on the login interface, in these two articles [jQuery form verification submission: front-end verification one][jQuery form verification submission: front-end verification二] also gives you a relevant introduction. Friends who need it can choose to refer to it.

Below I will introduce to you thephp background filtering data space verificationmethod through a simple code example.

1. Login.html code example:

    登录  

The form here mainly submits data to check1.php through post method.

2. Check1.php code example:


      

The effect of the front desk login interface is as follows:

How to filter spaces in post submission data in PHP

If we delete the trim function in the above check1.php code.

Note: The trim() function means to remove blank characters or other predefined characters on both sides of the string.

Then when we enter the user name with spaces, the result is as shown below:

How to filter spaces in post submission data in PHP

As shown in the picture, the user name does not exist. This is because We do not perform data filtering operations in the background.

When we process the submitted data according to the complete code of check1.php above, even the user name with spaces will show successful login.

The effect is as follows:

How to filter spaces in post submission data in PHP

As shown in the figure, we successfully filtered the spaces before and after the user name.

In fact, in our daily process of logging in to various backends, some of our friends must be accustomed to adding spaces when entering user names or passwords. Then you can decide whether you need to filter spaces according to the needs of your own project.

This article is an introduction to the method of filtering spaces in PHP data submitted by posts. It is easy to understand and I hope it will be helpful to friends in need!

If you want to know more about PHP, you can follow the PHP Chinese websitePHP Video Tutorial, everyone is welcome to refer to and learn!

The above is the detailed content of How to filter spaces in post submission data in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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