将 bbcode 替换为 html 标签


Replace bbcode with html tags

我正在编写一个 ittle 脚本,用相应的 html 标签替换 bbcode。bbcode 和 html 标签都存储在数据库中。这是我对 [b][/b] 的实际代码,但它不起作用

function bbcode($matches)
{
$conn = mysqli_connect('127.0.0.1','root','','esame') or die("Connection failed: " . $conn->connect_error);
foreach ($matches as $match)
    {
    $query = mysqli_query($conn,"SELECT html FROM `bbcode` WHERE bbcode='{$match}' ");
        while ($html = mysqli_fetch_array($query,MYSQLI_ASSOC))
        {
        return 'Html: '.$html['html'];
        }
    $conn->close();
    }
}
$regex = '/'[b'](.+)'['/b']/is';
echo '<br>'.preg_replace_callback($regex,"bbcode",$text).'<br>';
$str = "[list=1]'n[*]Камиль [/*]'n[*]Хисматуллин [/*]'n[*]живет в Урюпинске [/*]'n[/list]"; 
$advanced_bbcode = array(
    '/(?si)''[list=''d+''](.*?)''[''/list'']/',
    '/(?si)''[''*''](.*?)''[''/''*'']/'
);
$advanced_html = array(
    '<ol>$1</ol>',
    '<li>$1</li>'
);
$text = preg_replace($advanced_bbcode, $advanced_html, $str);
echo $text;