The PHP trim () function is generally used to remove whitespace characters (or other characters) at the beginning and end of a string, and is generally used to process the received user data on the server side, so as not to store the user's input blank space in the database, the next time the data is compared.
The function has two parameters, the second one can be empty, and the format is as follows:
Trim (String $str [, string $character _mask = "\t\n\r\0\x0b"]);
The $STR is a string that needs to be processed, and if $character_mask is not empty, it will only clear $character_mask of the required characters written on it; if the second argument $character_mask is empty, the following characters are filtered:
- "" (ASCII (0x20)), plain space.
- "\ T" (ASCII 9 (0x09)), tab.
- "\ n" (ASCII (0x0A)), line break.
- "\ R" (ASCII (0x0D)), carriage return.
- "\" (ASCII 0 (0x00)), null byte character.
- "\x0b" (ASCII One (0x0B)), Vertical tab.
After data processing, the filtered string is returned.
Set a parameter $str:
<?php$data = "I have a space"; $data 2 = ";"; echo $data. $data 2;echo "<br>", echo trim ($data) $data 2;echo "<br>";
Trim function whitespace removal effect
Obviously, after the trim function is processed, the whitespace of the string data is removed.
We add a second parameter to see the effect:
<?php$data = "I have a space"; $data 2 = ";"; echo $data. $data 2;echo "<br>", echo trim ($data, ' \ t '). $data 2;//Specifies to delete the tab symbol \techo "<br>";
Trim Remove Tabs
Obviously, our data does not have a tab, so even if the trim is processed, our space is still there.
My blog Original: PHP trim () function and how to use
http://www.wangtuizhijia.com/archives/125
The function of the PHP trim () function and how to use it