【问题标题】:Best way to turn this list bbcode to html?将此列表 bbcode 转换为 html 的最佳方法?
【发布时间】:2012-12-09 16:52:35
【问题描述】:

说有一个这样的bbcode列表:

[list]
[*]something
[*]something2
[/list]

在 php 中将其转换为 html 列表的最佳方法是什么?

【问题讨论】:

  • 也许using the BBCode extension 值得一试。
  • 鉴于扩展需要服务器端安装,您可能希望使用纯 PHP 库。其中有很多。目前排名第一的 Google 结果是NBBC

标签: php regex bbcode


【解决方案1】:
$string = '[list]
[*]something
[*]something2
[/list]';

$regex = array(
 '/\[list\](.*?)\[\/list\]/is' => '<ul>$1</ul>',
 '/\[\*\](.*?)(\n|\r\n?)/is' => '<li>$1</li>'
);


echo preg_replace(array_keys($regex), array_values($regex), $string);

【讨论】:

  • 列表中的列表呢?
猜你喜欢
  • 2021-10-16
  • 1970-01-01
  • 2015-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多