Why use trim () to trim user input data? -Php Tutorial

Source: Internet
Author: User
Why use trim () to trim user input data? I have seen many programs use trim to trim user input data,
Why?

The introduction in the book says that it is for security.

I am wondering, which of the following is a detailed explanation?


Reply to discussion (solution)

Trim can be ???? Space.
If ?? Entered ?? Yes
$ Data = '';
So? Use if ($ data = '')? Returns false, because? Use? Yes? Incoming ??, Only no? Is a space.
But me ?? Check if? All input ?? All are spaces, right? Intentionally? Of ,??? Null character? .
So trim ($ data ?? Space? After division, if? If there are characters, it means to use? Yes? Incoming ??, In addition, you can? Space used? Division.

Example $ data = 'aaa ';
Echo trim ($ data); // aaa

It has nothing to do with security and does not need to be used.

When registering and logging in, it is inevitable that multiple spaces will be mistakenly operated. at least remove the first and last spaces.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.