php regex [b] to

后端 未结 2 2013
后悔当初
后悔当初 2020-11-30 15:56
  \"\'\\[b\\](.*?)\\[/b\\]\'is\",

Is my current RegEx working. But I want to change the [] to be <> instead. But it doesn\'t work... What more t

相关标签:
2条回答
  • 2020-11-30 16:22

    Try ~ as a delimiter instead

    preg_match("~<b>(.*?)</b>~is", $text, $b);
    
    0 讨论(0)
  • 2020-11-30 16:31

    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
    0 讨论(0)
提交回复
热议问题