【问题标题】:PHP str_replace with array() not working ? (have example)PHP str_replace with array() 不起作用? (有例子)
【发布时间】:2025-11-24 10:05:02
【问题描述】:

[代码]

echo str_replace(array('(', ')'), '', "(test) i'm test"); exit;

[运行]

(test) i'm test

我想从这个文本中删除括号,但它不起作用?

【问题讨论】:

  • 不,它有效:3v4l.org/NFG0c
  • @Nattapat 你在输出中得到了什么!!它运作良好。

标签: php str-replace


【解决方案1】:

此代码从以下字符串中删除括号 ()

(test) i'm test"

$string = "(test) i'm test";
echo str_replace(array( '(', ')' ), '', $string);

使用str_replace()函数后的结果:

test i'm test"

【讨论】:

  • 如果您能在答案中添加一个简短的解释,那就太好了。它将帮助 OP 和其他人了解解决方案。
  • 当然。我会添加它