从整场比赛中删除BBcode标签

时间:2016-05-19 12:27:26

标签: php arrays preg-match-all

如何使用所有字符串获取数组。

$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]
        )

)

最后没有“文字内部”文字。

1 个答案:

答案 0 :(得分:0)

的preg_replace?

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

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