Home > Backend Development > PHP Tutorial > php 为什么 trim($str, '-') 无法删除 '-' ?

php 为什么 trim($str, '-') 无法删除 '-' ?

WBOY
Release: 2016-06-06 20:44:06
Original
939 people have browsed it

如题,具体代码如下

<code><?php $trimmed = trim("go-go-go", '-');
    var_dump($trimmed);
?>
</code>
Copy after login
Copy after login

输出为

<code>string(8) "go-go-go"
</code>
Copy after login
Copy after login

请问为什么无法删除字符串中的 - 符号?第二个参数不是用来指定过滤符号的吗?

谢谢

回复内容:

如题,具体代码如下

<code><?php $trimmed = trim("go-go-go", '-');
    var_dump($trimmed);
?>
</code>
Copy after login
Copy after login

输出为

<code>string(8) "go-go-go"
</code>
Copy after login
Copy after login

请问为什么无法删除字符串中的 - 符号?第二个参数不是用来指定过滤符号的吗?

谢谢

trim() 只能删除 字符串 两侧的
可以使用楼上的方法 替换为空格

str_replace('','-','go-go-go');

替换用str_replace

Related labels:
php
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