: This article describes how to use the trim function in PHP to remove spaces and special characters from the left and right sides of a string. For more information about PHP tutorials, see. This example describes how PHP uses the trim function to remove leading spaces and special characters from strings. We will share this with you for your reference. The details are as follows:
The trim () function in PHP is defined as follows:
Trim (string, charlist)
Parameters are described as follows:
String is required. Specifies the string to be checked.
Charlist
Optional. Specifies which characters are deleted from the string. If omitted, all the following characters are removed:
"\ 0"-NULL
"\ T"-tab
"\ N"-line feed
"\ X0B"-vertical tab
"\ R"-Press enter
""-Space
The sample code is as follows:
<? Php $ str = "\ r (: @ _ @ this site provides a large number of excellent script and material downloads @ _ @:)"; echo trim ($ str); echo"
"; Echo trim ($ str," \ r (: :) ");?>
The running result is as follows:
(: @ _ @ Download of a large number of excellent scripts and materials on this site _:) @ download of a large number of excellent scripts and materials on this site @_@
I hope this article will help you with PHP programming.
The preceding section describes how to use the trim function in PHP to remove spaces and special characters from the left and right sides of the string, including some content. if you are interested in the PHP Tutorial.