- <?php
- function parse_bb($text)
- {
- while (preg_match('#(?<!UNKNOWN:)\[(.+)(?:=(.*?))?\](.*?)\[\/\1\]#s',$text))
- {
- $text = preg_replace_callback('#(?<!UNKNOWN:)\[(.+)(?:=(.*?))?\](.*?)\[\/\1\]#s', 'parse_bb_callback', $text);
- }
- return nl2br($text);
- }
- function parse_bb_callback($hit)
- {
- $tag = $hit[1];
- $attr = $hit[2];
- $encl = $hit[3];
- switch ( $tag )
- {
- case 'b': case 'li': case 'ol': case 'i': case 'u': case 'h3':
- return "<$tag>$encl</$tag>";
- break;
- case 'img':
- return "<img src=\"$attr\" alt=\"$encl\" />";
- break;
- case 'lnk':
- if ( $encl == '' )
- {
- return "<a href=\"$attr\" target=\"_blank\">$attr</a>";
- }
- return "<a href=\"$attr\">$encl</a>";
- break;
- case 'mailto':
- $mail = preg_replace( "/(.)/se", " '&#' . ord( '\\1' ) . ';' ", $attr );
- return "<a href=\"mailto:$mail\">$mail</a>";
- break;
- case 'html':
- $encl = html_entity_decode($encl);
- $encl = str_replace('&', '&', $encl);
- return $encl;
- break;
- default:
- return "UNKNOWN:$hit[0]";
- }
- }
- $html='[ol]
- [li]list item[/li]
- [li]another list item[/li]
- [/ol]
- [i][b]test[/b]ing[/i]
- [img=path]image[/img]
- [othertag=attr]encl[/othertag]';
- echo parse_bb($html);
- ?>
Posted by Anonymous on Mon 6 Oct 19:19 (modification of post by Anonymous view diff)
report abuse | View followups from Anonymous | download | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.