Home  >  Article  >  Backend Development  >  PHP uses trim function to remove left and right spaces and special characters from strings_php tips

PHP uses trim function to remove left and right spaces and special characters from strings_php tips

WBOY
WBOYOriginal
2016-05-16 20:00:361166browse

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

The sample code is as follows:

<&#63;php
 $str="\r\r(:@_@  脚本之家 提供大量优秀脚本与素材下载  @_@:)   ";
 echo trim($str);
 echo "<br/>";
 echo trim($str,"\r\r(: :)");
&#63;>

The running results are as follows:

(:@_@ 脚本之家 提供大量优秀脚本与素材下载 @_@:)
@_@ 脚本之家 提供大量优秀脚本与素材下载 @_@

I hope this article will be helpful to everyone in PHP programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn