【发布时间】:2019-12-02 18:59:06
【问题描述】:
我正在尝试使 ABBC3 与 PHP 7.3 和 PHPBB 3.0.14 一起使用,因为我无法迁移到 PHPBB 3.3,因为未移植到扩展和主题的 MOD 存在很多问题(绝对解决)。
我已经在PHPBB forum 寻求帮助但没有运气,因为不再支持 3.0.x 和 3.1.x 版本。
所以在尝试理解 bbcode 功能数十小时后,我几乎准备好了。
当消息中只有一个 bbcode 时,我的代码有效。但在 bbcode 较多或与文本混合时不起作用。
所以我想获得一些帮助来解决这部分问题,以使一切正常。
在includes/bbcode.php这个函数的第98行:
$message = preg_replace($preg['search'], $preg['replace'], $message);
返回的是这样的:
$message = "some text $this->Text_effect_pass('glow', 'red', 'abc') another text. $this->moderator_pass('"fernando"', 'hello!') more text"
对于这条消息:
一些文本 [glow=red]abc[/glow] 另一个文本。
[mod="fernando"]你好![/mod] 更多文字
上面 preg_replace 的输入只是为了上下文:
"some text [glow=red:mkpanc3g]abc[/glow:mkpanc3g] another text. [mod="fernando":mkpanc3g]hello![/mod:mkpanc3g]"
所以基本上我必须将此字符串拆分为有效的表达式以应用 eval() 然后连接所有内容。像这样:
$message = "some text". eval($this->Text_effect_pass('glow', 'red', 'abc');) . "another text " . eval($this->moderator_pass('"fernando"', 'hello!');). "more text"
在这种特定情况下,'"fernando"' 中还留有双引号。
我知道将 eval() 应用于用户输入是不安全的,所以我想制作某种类型的 preg_match 和/或 preg_split获取 () 内的值作为参数传递给我的函数。
功能基本是:
Text_effect_pass()
moderator_pass()
anchor_pass()
simpleTabs_pass()
我在想这样的事情(请忽略这里的错误):
if(preg_match("/$this->Text_effect_pass/", $message)
{
then split the string and get value inside of() and remove extra single or double quotes.
after:
$textEffect = Text_effect_pass($value[0], $value[1], $value[2]);
Finally concatenate everything:
$message = $string[0] .$textEffect. $string[1];
}
if(preg_match("/$this->moderator_pass/", $message)
{
.....
}
P.S.:由于使用了 e 修饰符,ABBC3 与 PHP 7.3 不兼容。我已经编辑了所有内容以删除修饰符。
在这里你可以看到它单独工作:
有人可以帮帮我吗?
【问题讨论】: