Removing string inside brackets

前端 未结 5 1610
渐次进展
渐次进展 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:15

    $str = "Lorem ipsum dolor
    [ Context are found on www.example.com ]
    some text here. Text here. [test] Lorem ipsum dolor."; $str = preg_replace('~\[[^]]*?www\.example\.com[^]]*\]~si', "", $str); var_dump($str);

    OUTPUT

    string(83) "Lorem ipsum dolor

    some text here. Text here. [test] Lorem ipsum dolor."

    PS: It will work with line broken in multiple lines.

提交回复
热议问题