php regex [b] to <b>

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 05:42:24
Gordon

There are various BBCode parsers available for PHP, for instance

which allows you to simply define your replacement rules by hand:

echo bbcode_parse(
    bbcode_create(
        array(
            'b' => array(
                'type'      => BBCODE_TYPE_NOARG,
                'open_tag'  => '<b>',
                'close_tag' => '</b>'
            )
        )
    ),
    '[b]Bold Text[/b]'
);
// prints <b>Bold Text</b>

Also check the various similar questions about BBCode Parsers:

genesis

Try ~ as a delimiter instead

preg_match("~<b>(.*?)</b>~is", $text, $b);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!