【问题标题】:remove BBcode tags from whole match从整个匹配中删除 BBcode 标签
【发布时间】:2016-05-19 12:27:26
【问题描述】:

如何获取包含所有字符串的数组。

$str = "This is some a text with [b]Bold[/b] and [i]Italic[/i] elements inside";

preg_match_all("/.*(\[.+\]).*/isU",$str,$matches);

print_r($matches);

我只得到:

Array (
    [0] => Array
        (
            [0] => This is a text with [b]
            [1] => Bold[/b]
            [2] =>  and [i]
            [3] => Italic[/i]
        )

    [1] => Array
        (
            [0] => [b]
            [1] => [/b]
            [2] => [i]
            [3] => [/i]
        )

)

最后没有“内部元素”文本。

【问题讨论】:

  • 为您展示理想/预期的结果

标签: php arrays preg-match-all


【解决方案1】:

Preg_replace?

$new_str = preg_replace("/(\[.*?\])/", "", $str);

http://www.phpliveregex.com/p/fKH

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-10
    • 2015-06-17
    • 2011-10-10
    相关资源
    最近更新 更多