instead. But it doesn\'t开发者_StackOverflow社区 work... What more then just the [] do I need to" />
开发者

php regex [b] to <b>

  "'\[b\](.*?)\[/b\]'is",

Is my current RegEx working. But I want to change the [] to be <> instead. But it doesn't开发者_StackOverflow社区 work... What more then just the [] do I need to change.


There are various BBCode parsers available for PHP, for instance

  • http://www.php.net/manual/en/book.bbcode.php

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:

  • https://stackoverflow.com/search?q=bbcode+php


Try ~ as a delimiter instead

preg_match("~<b>(.*?)</b>~is", $text, $b);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜