Home > Backend Development > PHP Tutorial > 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
Release: 2016-05-16 20:00:36
Original
1187 people have browsed it

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;>

Copy after login
The running results are as follows:

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

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template