从字符串中替换{} []()括号之间的所有内容

Vis*_*hnu 6 php regex string replace preg-replace

嗨,我想删除大括号内的所有内容,例如,如果字符串是helloz,我希望输出只是helloz 我使用下面的代码,但必须有一些简单的方法来做.有人请告诉我how.thanks

[hi] helloz [hello] (hi) {jhihi}
Run Code Online (Sandbox Code Playgroud)

Dam*_*eem 17

这应该工作:

$name = "[hi] helloz [hello] (hi) {jhihi}";
echo preg_replace('/[\[{\(].*[\]}\)]/U' , '', $name);
Run Code Online (Sandbox Code Playgroud)

将它粘贴到某处,如:http://writecodeonline.com/php/,看它是否有效.

  • 如果你在其中一个大括号内有另一个右大括号,你会遇到问题`$ name ="[h)i] helloz [hello](hi){jhihi}";` (2认同)