Home > Article > Backend Development > PHP uses trim function to remove left and right spaces and special characters from strings_php tips
The example in this article describes how PHP uses the trim function to remove left and right spaces and special characters from a string. Share it with everyone for your reference, the details are as follows:
The trim() function in PHP is defined as follows:
trim(string,charlist)
The parameter description is as follows:
string Required. Specifies the string to check.
charlist
Optional. Specifies which characters are removed from the string. If omitted, all following characters are removed:
"
"t" - tab
"n" - newline
"x0B" - vertical tab
"r" - carriage return
" " - space
<?php $str="\r\r(:@_@ 脚本之家 提供大量优秀脚本与素材下载 @_@:) "; echo trim($str); echo "<br/>"; echo trim($str,"\r\r(: :)"); ?>
(:@_@ 脚本之家 提供大量优秀脚本与素材下载 @_@:) @_@ 脚本之家 提供大量优秀脚本与素材下载 @_@