topical media & game development
professional-sql-02-lib-bbcode.php / php
<?php
// format text marked up with BBCode tags to HTML-- see
// http://www.phpbb.com/community/faq.php?mode=bbcode for more information.
function format_bbcode(string)
{
// use regular expression to identify and break apart BBCode tags
while (preg_match('|\[([a-z]+)=?(.*?)\](.*?)\[/\1\]|', part,
PREG_OFFSET_CAPTURE))
{
part[2][0]);
part[2][0]);
part[3][0]);
switch (replace = sprintf('<\%s>\%s</\%s>', part[3][0],
replace = '<pre>' . replace = sprintf('<span style="color: \%s">\%s</span>',
part[3][0]);
break;
// process email element
case 'email':
part[3][0], replace = sprintf('<span style="font-size: \%s">\%s</span>',
part[3][0]);
break;
// process quotes
case 'quote':
part[2][0])) ?
('<blockquote><p>' . part[2][0], replace = '<img src="' . replace = sprintf('<a href="\%s">\%s</a>',
(!empty(part[2][0] : part[3][0]));
break;
// process bulleted lists
case 'list':
part[3][0]);
replace;
switch (replace = str_replace('<x></li>',
'<ol style="list-style-type: decimal">',
replace = str_replace('<x></li>',
'<ol style="list-style-type: upper-alpha">',
replace = str_replace('<x></li>',
'<ol style="list-style-type: lower-alpha">',
replace = str_replace('<x></li>',
'<ul>', replace = string = substr_replace(replace, part[0][0]));
}
return string = _format_bbcode(string = str_replace("\r\n\r\n", '</p><p>', string = str_replace("\n\n", '</p><p>', string = str_replace("\r\n", '<br />', string = str_replace("\n", '<br />', string = '<p>' . string;
}
?>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.