Get the App
SLTechnology News&Howtos  ›  Development  › 

What does trim mean in php

Shulou Source: shulou.com Published: 2022-06-02 04:41:13 12月01日 Update

Editor to share with you what trim means in php, I believe most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

Php's trim is a built-in function to remove white space characters or other characters at the beginning and end of a string. It is generally used on the server to process the received user data so as to avoid storing the spaces mistakenly entered by the user to the database.

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

The function and usage of PHP trim () function

The PHP trim () function is generally used to remove white space characters (or other characters) at the beginning and end of a string. It is generally used on the server to process the received user data, so as to avoid storing the spaces mistakenly entered by the user to the database, and make an error next time when comparing the data.

The function takes two arguments, and the second can be empty in the following format:

Trim (string $str [, string $character_mask = "\ t\ n\ r\ 0\ x0B"])

$str is the string to be processed. If $character_mask is not empty, only the clear characters written on $character_mask will be clear. If the second parameter, $character_mask, is empty, the following characters will be filtered:

"(ASCII 32 (0x20)), a normal space character.

"\ t" (ASCII 9 (0x09)), tabs.

"\ n" (ASCII 10 (0x0A)), newline character.

"\ r" (ASCII 13 (0x0D)), carriage return.

"\ 0" (ASCII 0 (0x00)), empty byte character.

"\ x0B" (ASCII 11 (0x0B)), vertical tab.

After the data is processed, the filtered string is returned.

Set a parameter $str:

Tags: Characters data processing functions strings spaces parameters users tabs tabs articles meaning clarity content database white space head and tail storage service input Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Information Apple NVidia MariaDB