-3

Say have have a bbcode list done like this:

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

What would be the best way in php to turn that into a html list?

hakre
  • 193,403
  • 52
  • 435
  • 836
NaughtySquid
  • 1,947
  • 3
  • 29
  • 44
  • 1
    Maybe [using the BBCode extension](http://php.net/manual/en/book.bbcode.php) would be worth a try. – Martin Ender Dec 09 '12 at 16:55
  • 1
    Given that the extension requires server-side installation, you may want to use a pure-PHP library instead. There are *plenty* of these. The #1 Google result right now is [NBBC](http://nbbc.sourceforge.net/). – Charles Dec 09 '12 at 17:42

1 Answers1

4
$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);
Prash
  • 1,915
  • 3
  • 20
  • 32