At 17:19 09.11.2002, Jens Lehmann said:
--------------------[snip]--------------------
>Hi out there,
>
>I encountered a lot of problems while trying to convert a list
>in Forum-Code (like UBB-Code).
>
>[list]
>[*] item 1
>[*] item 2
>[*] item 3
>[/list]
>
>should be converted to
>
><ul>
><li>item 1</li>
><li>item 2</li>
><li>item 3</li>
></ul>
--------------------[snip]--------------------
Maybe you could use this solution. It supports newlines and special
characters in the item's data as well:
<?php
function ubb2ul($src)
{
// retrieve the items
preg_match('/\[list\]\n?(.*?)\n?\[\/list\]/is', $src, $ar);
// now split the results by (opt) newline, followed by '[*]', (opt)
followed by whitespace
$ar = preg_split('/\n*\s*\[\*\]\s*/s', $ar[1]);
// $ar[0] is empty since the first element begins with a [*], chop
it off
array_shift($ar);
// apply htmlentities
for ($i = 0, $c = count($ar); $i < $c; ++$i)
$ar[$i] = nl2br(htmlentities($ar[$i]));
// finally construct the list
$result = '<ul><li>' . join("\n\t<li>", $ar) . "\n</ul>\n";
return $result;
}
$ubb = '[list]
[*] item 1 ��� line 1
item 1 line 2
[*] item 2
[*] item 3
[/list]';
echo ubb2ul($ubb);
?>
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php