Home >php教程 >php手册 >PHP和sql去除字符串首尾特定字符或空格

PHP和sql去除字符串首尾特定字符或空格

WBOY
WBOYOriginal
2016-06-13 09:52:161714browse

下面我来一起来看一个关于PHP和sql去除字符串首尾特定字符或空格实现,这里我们只要使用trim即可哦。

PHP去除字符串首尾特定字符函数trim()

  $a="(a,b,c,)"; echo $a."
"; //输出:(a,b,c,)
$b=trim($a,"()"); //去除字符串首尾含有的字符“(”或“)” echo $b."
"; //输出:a,b,c,
$c=trim($a,"(,)"); //去除字符串首尾含有的字符“(”、“,”或“)” echo $c."
"; //输出:a,b,c
  ?>
  输出结果: (a,b,c,) a,b,c, a,b,c

在sql中函数trim()用途为去除首尾空格,ltrim()为去除字符串左侧空格,rtrim()为去除字符串右侧空格。

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