希望使用 PHPBB3 的函数在 PHP 中解析 BB 代码。我已经走到这一步了:
<?php
include_once("../../forum/includes/functions_content.php");
$text = "[b]bold text here[/b] not bold here";
$uid = $bitfield = $options = '';
echo("parsing");
echo generate_text_for_storage($text, $uid, $bitfield, $options, true, true, true);
echo("finished");
?>
但是它回显 parsing
但之后不会继续。我期望输出是这样的:
<b>bold text here</b> not bold here
非常感谢任何帮助!
编辑
没有答案仍然有效。我正在寻找一个 Standalone php 页面,它使用 PHPBB3 的 BBCode 解析器将给定的 BB 代码字符串转换为 HTML 字符串。
最佳答案
生成 bbcodes 是一个 2 步过程,你做第一步(第一次通过)
generate_text_for_storage
用于将 bbcode 存储在数据库中,它存储为 bbcode 因为您可以更改 bbcode 而无需重新解析旧消息。
您正在寻找的另一个功能是
generate_text_for_display
PHPBB 有一个 wiki 列出了这样的东西
https://wiki.phpbb.com/Tutorial.Parsing_text
https://wiki.phpbb.com/Generate_text_for_display
是您要查找的页面。
或者你可以直接使用 bbcode 类,代码也可以工作
$bbcode = new bbcode(base64_encode($bbcode_bitfield));
$bbcode->bbcode_second_pass($post_text, $posts_row['bbcode_uid'], $posts_row['bbcode_bitfield']);
$post_text = smiley_text($post_text);
$post_text = censor_text($post_text);
你需要
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
最后一个工作
2 函数方法的完整代码,带输出
<?php
ini_set('display_errors', 1);
define('IN_PHPBB', true);
$phpbb_root_path = './forum/';
$phpEx = "php";
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('viewforum');
$text = "[b]bold text here[/b] not bold here";
$uid = $bitfield = $options = '';
echo("parsing");
echo generate_text_for_storage($text, $uid, $bitfield, $options, true, true, true);
var_dump($text);
$text = generate_text_for_display($text, $uid, $bitfield, OPTION_FLAG_BBCODE );
var_dump($text);
echo("finished");
哪些输出
parsing
string '[b:1vhn6cjx]bold text here[/b:1vhn6cjx] not bold here' (length=53)
array (size=1)
0 => int 1
string '<span style="font-weight: bold">bold text here</span> not bold here' (length=67)
finished
bb 代码转换是一个 2 步过程,使用户和发布者都可以灵活地自定义帖子的 View 。您将需要先使用第一个函数处理文本,然后再进行第二次处理以获取 html
关于php - 解析PHPBB3的BB代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21939777/