#flipcode

#flipcode
Welcome to the chatterbox... 
#flipcode forumspace!

Browsing Forum/Site Related

Some other BBcode stuff ... ;o)


 




 
Psor (53)Some other BBcode stuff ... ;o) - 2006-06-06 17:49:39
Avatar of user Psor
Registered: unknown
Posts: 349

If you don\'t mind you could add some other bbcodes like those:

Center, Underline, List, Bold, Italic, ... blaablaa :D

example:


    // [center]Centered text[/center]
   $s = preg_replace(\"/\\[center\\]((\\s|.)+?)\\[\\/center\\]/i\", \"<center>\\\\1</center>\", $s);
   // [list]List[/list]
   $s = preg_replace(\"/\\[list\\]((\\s|.)+?)\\[\\/list\\]/\", \"<ul>\\\\1</ul>\", $s);
   // [list=disc|circle|square]List[/list]
   $s = preg_replace(\"/\\[list=(disc|circle|square)\\]((\\s|.)+?)\\[\\/list\\]/\", \"<ul type=\\\"\\\\1\\\">\\\\2</ul>\", $s);
   // [list=1|a|A|i|I]List[/list]
   $s = preg_replace(\"/\\[list=(1|a|A|i|I)\\]((\\s|.)+?)\\[\\/list\\]/\", \"<ol type=\\\"\\\\1\\\">\\\\2</ol>\", $s);
   // [*]
   $s = preg_replace(\"/\\[\\*\\]/\", \"<li>\", $s);
   // [b]Bold[/b]
   $s = preg_replace(\"/\\[b\\]((\\s|.)+?)\\[\\/b\\]/\", \"<b>\\\\1</b>\", $s);
   // [i]Italic[/i]
   $s = preg_replace(\"/\\[i\\]((\\s|.)+?)\\[\\/i\\]/\", \"<i>\\\\1</i>\", $s);
   // [u]Underline[/u]
   $s = preg_replace(\"/\\[u\\]((\\s|.)+?)\\[\\/u\\]/\", \"<u>\\\\1</u>\", $s);
   // [u]Underline[/u]
   $s = preg_replace(\"/\\[u\\]((\\s|.)+?)\\[\\/u\\]/i\", \"<u>\\\\1</u>\", $s);
   // Maintain spacing
   $s = str_replace(\"  \", \"  \", $s);

nb: Would be cool if you could also maintain the spacing. :D ;)

take care

psor

Psor (53)Some other BBcode stuff ... ;o) - 2006-06-06 18:01:01
Avatar of user Psor
Registered: unknown
Posts: 349

Erm, ... the "NoBreakingSpace" is getting stripped in the [ code ] bbcode ... :/

So here an example if you wanna have a look at it. ;)

take care

psor

Dirtysouthafrican (2)Some other BBcode stuff ... ;o) - 2006-06-07 07:30:23
Avatar of user Dirtysouthafrican
Registered: unknown
Posts: 312

Psor wrote:

example:


    // [center]Centered text[/center]
   $s = preg_replace("/\[center\]((\s|.)+?)\[\/center\]/i", "<center>\\1</center>", $s);
   // [list]List[/list]
   $s = preg_replace("/\[list\]((\s|.)+?)\[\/list\]/", "<ul>\\1</ul>", $s);
   // [list=disc|circle|square]List[/list]
   $s = preg_replace("/\[list=(disc|circle|square)\]((\s|.)+?)\[\/list\]/", "<ul type=\"\\1\">\\2</ul>", $s);
   // [list=1|a|A|i|I]List[/list]
   $s = preg_replace("/\[list=(1|a|A|i|I)\]((\s|.)+?)\[\/list\]/", "<ol type=\"\\1\">\\2</ol>", $s);
   // [*]
   $s = preg_replace("/\[\*\]/", "<li>", $s);
   // [b]Bold[/b]
   $s = preg_replace("/\[b\]((\s|.)+?)\[\/b\]/", "<b>\\1</b>", $s);
   // [i]Italic[/i]
   $s = preg_replace("/\[i\]((\s|.)+?)\[\/i\]/", "<i>\\1</i>", $s);
   // [u]Underline[/u]
   $s = preg_replace("/\[u\]((\s|.)+?)\[\/u\]/", "<u>\\1</u>", $s);
   // [color=blue]Text[/color]
   $s = preg_replace("/\[color=([a-zA-Z]+)\]((\s|.)+?)\[\/color\]/i",
       "<font color=\\1>\\2</font>", $s);
   // [color=#ffcc99]Text[/color]
   $s = preg_replace("/\[color=(#[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9])\]((\s|.)+?)\[\/color\]/i",
       "<font color=\\1>\\2</font>", $s);
   // [size=4]Text[/size]
   $s = preg_replace("/\[size=([1-7])\]((\s|.)+?)\[\/size\]/i",
       "<font size=\\1>\\2</font>", $s);
   // [pre]Preformatted[/pre]
   $s = preg_replace("/\[pre\]((\s|.)+?)\[\/pre\]/i", "<tt><nobr>\\1</nobr></tt>", $s);
   // Maintain spacing
   $s = str_replace("  ", "  ", $s)

Testing


 
You need to log in in order to reply to this topic.
generated:January 6, 2009, 3:12 am
Generated on January 6, 2009, 3:12 am



© 2007 Lionel Brits

This page validates as XHTML 1.1 RSS 2.0 posts


Theme © 2006 Lionel Brits