Remove the space before and after.
Suppose there is a string "DDD dd D" that becomes "DDD DD D" after trim ().
You can remove extra spaces (including tabs) on either side, but you can't remove the middle space.
The trim () function in PHP is the same as the trim () function in ASP, and if you touch an ASP, it will be used naturally.
The usage is simple, add the following to the variable that you want to remove the space:
<?php
Echo Trim ($ variable);
?>
Generally used in the user's password processing.
Definitions and usage
The trim () function deletes white space characters and other predefined characters from both ends of the string.
Grammar
Trim (string,charlist) parameter description
String required. Specify the string to check.
Charlist Optional. Specify the string to convert. If this argument is omitted, all of the following characters are deleted:
"" "-NULL
"\ T"-tab
"\ n"-New line
"\X0B"-Portrait list character
"\ r"-Carriage return
""-Plain white space character
Example 1
Copy Code code as follows:
<body>
<?php
$str = "Hello world!";
echo "without Trim:". $STR;
echo "<br/>";
echo "with Trim:". Trim ($STR);
?>
<body>
Output:
Copy Code code as follows:
Without Trim:hello world!
With Trim:hello world! HTML Source code:
Example 2
Copy Code code as follows:
<?php
$str = "\r\nhello world!\r\n";
echo "without Trim:". $STR;
echo "<br/>";
echo "with Trim:". Trim ($STR);
?>
Output:
Without Trim:hello world!
With Trim:hello world! Html