Home > Backend Development > PHP Tutorial > PHP and sql remove specific characters or spaces at the beginning and end of a string_PHP tutorial

PHP and sql remove specific characters or spaces at the beginning and end of a string_PHP tutorial

WBOY
Release: 2016-07-13 10:50:38
Original
1178 people have browsed it

Let me take a look at an implementation of removing specific characters or spaces at the beginning and end of a string in PHP and SQL. Here we only need to use trim.

PHP function trim() to remove specific characters at the beginning and end of a string

trim() 函数

$a="(a,b,c,)"; echo $a."
"; //Output: (a,b,c,)
$b=trim($a,"()"); //Remove the characters "(" or ")" contained at the beginning and end of the string echo $b."
"; //Output: a,b,c,
$c=trim($a,"(,)"); //Remove the characters "(", "," or ")" contained at the beginning and end of the string echo $c."
"; //Output: a,b,c
?>
Output result: (a,b,c,) a,b,c, a,b,c

In SQL, the function trim() is used to remove leading and trailing spaces, ltrim() is to remove spaces on the left side of a string, and rtrim() is used to remove spaces on the right side of a string.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632621.htmlTechArticleLet me take a look at the implementation of PHP and SQL to remove specific characters or spaces at the beginning and end of a string. Here we only need Just use trim. PHP function tr to remove specific characters from the beginning and end of a string...
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