Remove the space before and after.
Suppose there is a string "DDD dd D", after trim () becomes "DDD dd D".
If you can remove the extra space on both sides (including tabs), but not the middle space.
The trim () function in PHP is the same as the use of the trim () function in ASP, which is naturally used if you have been exposed to ASP.
The usage is simple, add the following in the variable where you want to remove the space:
Echo Trim ($ variable);
?>
Generally used in the user's password processing.
Definition and usage
The trim () function removes white-space characters and other predefined characters from both ends of the string.
Grammar
Trim (string,charlist) parameter description
string is required. Specifies the string to check.
Charlist is optional. Specifies the string to convert. If this argument is omitted, all of the following characters are removed:
"+"-NULL
"\ T"-tab
"\ n"-New line
"\x0b"-Vertical list character
"\ r"-Enter
""-Plain white space character
Example 1
Copy the Code code as follows:
$str = "Hello world!";
echo "without Trim:". $STR;
echo "
";
echo "with Trim:". Trim ($STR);
?>
Output:
Copy the Code code as follows:
Without Trim:hello world!
With Trim:hello world! HTML Source:
Example 2
Copy the Code code as follows:
$str = "\r\nhello world!\r\n";
echo "without Trim:". $STR;
echo "
";
echo "with Trim:". Trim ($STR);
?>
Output:
Without Trim:hello world!
With Trim:hello world! Html
The above describes the trim function in PHP implementation of the TRIM function code, including the trim function aspects of the content, I hope that the PHP tutorial interested in a friend helpful.