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 CodeThe code is as follows:
$str = "Hello world!";
echo "without Trim:". $STR;
echo "
";
echo "with Trim:". Trim ($STR);
?>
Output:
Copy CodeThe code is as follows:
Without Trim:hello world!
With Trim:hello world! HTML Source:
Example 2
Copy CodeThe code is 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
http://www.bkjia.com/PHPjc/318090.html www.bkjia.com true http://www.bkjia.com/PHPjc/318090.html techarticle Remove the space before and after. Assume that there is a string "dddddd", after trim () becomes "dddddd". If you can remove the extra spaces on both sides (including tabs), but not the middle space ...