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

php regex [b] to <b>

开发者 https://www.devze.com 2023-04-08 01:56 出处:网络
\"\'\\[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
  "'\[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

精彩评论

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

关注公众号