Reputation: 3254
I can't get my head around this and I could really use some help.
I want to replace text like this
[list]line 0
line 1
line 2
[/list]
with
<ul><li>line 0</li>
<li>line 1</li>
<li>line 2</li>
</ul>
It can appear several times in the string and it would be great if it can avoid adding empty list elements.
Upvotes: 0
Views: 273
Reputation: 968
preg_replace('#[list](.*?)[/list]', $data, $list);
$list[1] = explode("\n", $list);
$html = '<ul>';
foreach($list[1] as $li){
$html .= '<li>'.$li.'</li>';
}
$html .= '</ul>';
Upvotes: 1
Reputation: 14012
Here is my special BBParser. Spent ages on it.
Use it like this:
$parse = new bbParse();
$pageContent = $parse->bbtohtml($dbContent);
Upvotes: 3