PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
/**
* bbdecode/bbencode functions:
* Rewritten - Nathan Codding - Aug 24, 2000
* quote, code, and list rewritten again in Jan. 2001.
* All BBCode tags now implemented. Nesting and multiple occurances should be
* handled fine for all of them. Using str_replace() instead of regexps often
* for efficiency. quote, list, and code are not regular, so they are
* implemented as PDAs - probably not all that efficient, but that's the way it is.
*
* Note: all BBCode tags are case-insensitive.
*/
function bbencode($message, $is_html_disabled) {
// pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0).
// This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it.
$message = " " . $message;
// First: If there isn't a "[" and a "]" in the message, don't bother.
if (! (strpos($message, "[") && strpos($message, "]")) )
{
// Remove padding, return.
$message = substr($message, 1);
return $message;
}
//
for posting code (HTML, PHP, C etc etc) in your posts.
$message = bbencode_code($message, $is_html_disabled);
//
and
for posting replies with quote, or just for quoting stuff.
$message = bbencode_quote($message);
//
and
for (un)ordered lists.
$message = bbencode_list($message);
// and for bolding text.
$message = preg_replace("/\[b\](.*?)\[\/b\]/si", "<!-- BBCode Start --><B>\\1</B><!-- BBCode End -->", $message);
// and for italicizing text.
$message = preg_replace("/\[i\](.*?)\[\/i\]/si", "<!-- BBCode Start --><I>\\1</I><!-- BBCode End -->", $message);
// [SIZE= X] and [/SIZE] for small text.
$message = preg_replace("/\[SIZE={1}(.*?)\](.*?)\[\/SIZE\]/si", "<!-- BBCode Start --><font size="\\1">\\2</font><!-- BBCode End -->", $message);
// [font= X] and [/font] for small text.
$message = preg_replace("/\[FONT={1}(.*?)\](.*?)\[\/FONT\]/si", "<!-- BBCode Start --><font face="\\1">\\2</font><!-- BBCode End -->", $message);
// [color= X] and [/font] for small text.
$message = preg_replace("/\[COLOR={1}(.*?)\](.*?)\[\/COLOR\]/si", "<!-- BBCode Start --><font color="\\1">\\2</font><!-- BBCode End -->", $message);