Removing string inside brackets

前端 未结 5 1609
渐次进展
渐次进展 2021-01-24 12:42

Good day!

I would like some help in removing strings inside the square brackets and including the square brackets.

The string looks like this:

$str

5条回答
  •  一生所求
    2021-01-24 13:12

    The simplest method I can think of is using a regular expression to math everything between [ and ] then replace it with "". The code below will replace the string you used in the example. If the actual strings that need to be removed are more complex you can change the regular expression to match then. I recommend using regexpal.com for testing your regular expressions.

    $string = preg_replace("\[[A-Za-z .]*\]","",$string);

提交回复
热议问题