gpt4 book ai didi

php - 使用 php 在 html 页面中显示 bbcode

转载 作者:行者123 更新时间:2023-12-02 17:38:03 24 4
gpt4 key购买 nike

我已经是一个bbcode字符串$mybbcode = [b]Hello word[/b]
使用 php 我想在 html 页面中以 html 格式显示它。
例如:< div><b>hello word</b><div>

最佳答案

基本上其他人之后已经对您说过了,但是如果您在 Google 中搜索,您会很快看到很多相关信息和已完成的功能。这是一个示例:

function bbc2html($content) {
$search = array (
'/(\[b\])(.*?)(\[\/b\])/',
'/(\[i\])(.*?)(\[\/i\])/',
'/(\[u\])(.*?)(\[\/u\])/',
'/(\[ul\])(.*?)(\[\/ul\])/',
'/(\[li\])(.*?)(\[\/li\])/',
'/(\[url=)(.*?)(\])(.*?)(\[\/url\])/',
'/(\[url\])(.*?)(\[\/url\])/'
);

$replace = array (
'<strong>$2</strong>',
'<em>$2</em>',
'<u>$2</u>',
'<ul>$2</ul>',
'<li>$2</li>',
'<a href="$2" target="_blank">$4</a>',
'<a href="$2" target="_blank">$2</a>'
);

return preg_replace($search, $replace, $content);
}

仅适用于懒惰的程序员;)

我邀请您从为您的项目完成的所有代码中搜索并决定什么是最好的。

关于php - 使用 php 在 html 页面中显示 bbcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24200048/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com