希望使用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");
?>
Run Code Online (Sandbox Code Playgroud)
然而它回声parsing但在此之后不会继续.我期待输出符合以下几点:
<b>bold text here</b> not bold here
Run Code Online (Sandbox Code Playgroud)
任何帮助非常感谢!
编辑
没有答案仍然有效.我正在寻找一个独立的 php页面,它使用PHPBB3的BBCode解析器将BB代码字符串转换为HTML字符串.
生成 bbcode 分为 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);
Run Code Online (Sandbox Code Playgroud)
你会需要
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
Run Code Online (Sandbox Code Playgroud)
为了最后一个工作
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");
Run Code Online (Sandbox Code Playgroud)
哪个输出
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
Run Code Online (Sandbox Code Playgroud)
bb 代码转换是一个两步过程,为用户和发帖者提供了自定义帖子视图的灵活性。您需要先使用第一个函数处理文本,然后再处理第二次以获取 html
| 归档时间: |
|
| 查看次数: |
2553 次 |
| 最近记录: |