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(// internal function to replace BBCode tags with suitable HTML 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 (// process bold, italic and underline elements case 'b': case 'i': case 'u': replace = sprintf('<\ %s>\ %s</\ %s>', part[3][0], // process code element case 'code': replace = '<pre>' . </pre>'; break; // process color styling case 'color': replace = sprintf('<span style="color:\ %s">\ %s</span>', part[3][0]); break; // process email element case 'email':\ %s<\a>', part[3][0], // process size styling case 'size': replace = sprintf('<span style="font-size:\ %s">\ %s</span>', part[3][0]); break; // process quotes case 'quote': part[2][0])) ? ('<blockquote><p>' . </p></blockquote>') : sprintf('<blockquote><p>\ %s wrote:<br />\ %s</p>' . '</blockquote>', part[2][0], // process image element case 'img': replace = '<img src="' . // process hyperlink case 'url': replace = sprintf('<a href="\ %s">\ %s</a>', (!empty(part[2][0] : part[3][0])); break; // process bulleted lists case 'list': </li><li>', part[3][0]); <x>' . replace; switch (replace = str_replace('<x></li>', '<ol style="list-style-type: decimal">', </ol>'); break; case 'A': replace = str_replace('<x></li>', '<ol style="list-style-type: upper-alpha">', </ol>'); break; case 'a': replace = str_replace('<x></li>', '<ol style="list-style-type: lower-alpha">', </ol>'); break; default: replace = str_replace('<x></li>', '<ul>', </ul>'); break; } break; default: replace = string = substr_replace(replace, part[0][0])); } return // replace tags string = _format_bbcode(// clean up line endings and add paragraph and line break tags 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>' . </p>'; return 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.