【发布时间】:2017-07-29 21:40:01
【问题描述】:
以下问题: 上面“列表”中的“li”标签设置不正确,然后它就是。 我试图改变表达,但我还没有找到解决办法。
这是我的(缩短的)代码(以及所有其他遵循相同原理图的“bb”)
function bb($content) {
$search = array (
'#\[list\](.+)\[\/list\]#iUs',
'#\[list=1\](.+)\[\/list\]#iUs',
'#\[\*\](.*)\[/\*\]#iUs',
'#\[IMG\](.+)\[\/IMG\]#iUs'
);
$replace = array (
'<ul>$1</ul>',
'<ol>$1</ol>',
'<li>$1</li>',
'<img src="$1"/>'
);
$newtext = preg_replace($search, $replace, $content);
$newtext = nl2br($newtext);
$newtext = preg_replace('#<br />(\s*<br />)+#', '<br />', $newtext);
return $newtext;
}
print autolink(bb($NewsItemContent)); // http/s autolinking (later I'll add link preview)
内容将如下所示:
[h1]MAIN FEATURES[/h1] [list] [*]Doubles https://steamcommunity.com/games/227300/announcements/detail/1294067099912833659 [*]Background screen options [*]Changed light flares on the player and AI vehicles https://steamcommunity.com/games/227300/announcements/detail/1335730452506903011 [/list] [h1]MINOR CHANGES[/h1] [list][*]Auxiliary brakes system support (engine brake and retarder in one control element)[/*][*]Fixed licence plate change in states/countries where no city formats exist[/*][*]Fixed brake vs parking brake behavior[/*][*]Fixed tire noise of silent tires[/*][*]Retarder improvement (better cruise control behavior, no braking with throttle, icon when moving only)[/*][*]Steam Inventory support to allow for distributing rewards from upcoming World of Trucks events[/*][/list] If you wish to participate in the open beta, you can find this version in the public_beta branch on Steam. The way to access it is as follows: Steam client → LIBRARY → right click on Euro Truck Simulator 2 → Properties → Betas tab → public_beta → 1.28 public beta. No password required. During open betas, there is a dedicated beta site for World of Trucks, which is used to safely test all new features.
我希望有人可以帮助我, 干杯'
【问题讨论】:
-
您能否说明您要发送给
bb的内容? -
没有解决问题,但是这个
'#\[\*\\](.*)\[\/\*\\]#iUs'只匹配这个[*\]asdf[/*\].. 它应该是这个'#\[\*\](.*)\[/\*\]#iUs'另外,使用.*将匹配到行尾,甚至其他标签。 -
您的示例中有两种不同的 bbcode 项目语法:第一个仅使用
[*]开始新项目,第二个使用结束标记结束项目。哪一个是正确的? (我已经看过第一个但从未见过第二个) -
而且,由于您有 dot-all 修饰符,
.*实际上会直接跳到字符串的 end 并回溯以找到结束标记。 -
无论如何,您可以构建一个模式来处理第一个语法(没有结束标记)并删除最终的结束标记(如果有)。
标签: php regex preg-replace bbcode