BBcode help


New member
Two little function, just as an example!
I think you can understand it :p

function trans_char($content_to_trans){
   $trans_content = $content_to_trans;
   $trans_content = preg_replace("\n", "<br />", $trans_content);
   $trans_content = preg_replace("#\[list=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/list\]#si", "<li>\\2</li>", $trans_content); // *
   $trans_content = preg_replace("#\[color=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/color\]#si", "<font color=\"\\1\">\\2</font>", $trans_content); // *
   $trans_content = preg_replace("#\[size=([1-2]?[0-9])\](.*?)\[/size\]#si", "<font size=\"\\1\">\\2</font>", $trans_content);	
   $trans_content = preg_replace("#\[b\](.*?)\[/b\]#si", "<b>\\1</b>", $trans_content);
   $trans_content = preg_replace("#\[u\](.*?)\[/u\]#si", "<u>\\1</u>", $trans_content);
   $trans_content = preg_replace("#\[i\](.*?)\[/i\]#si", "<i>\\1</i>", $trans_content);
   $trans_content = preg_replace("#\[center\](.*?)\[/center\]#si", "<center>\\1</center>", $trans_content);		
   $trans_content = preg_replace("#\[img\]((ht|f)tp://)([^\r\n\t<\"]*?)\[/img\]#sie", "<img src=\"\\1\" border=\"0\">", $trans_content);	
   $trans_content = preg_replace("!(\[php\]|<\?)(.*?)(\[/php\]|\?>)!ise","php_and_code('\\2','\\1','\\3','PHP')", $trans_content);
   $trans_content = preg_replace("!(\[code\]|<\?)(.*?)(\[/code\]|\?>)!ise","php_and_code('\\2','\\1','\\3','CODE')", $trans_content); 
   $trans_content = preg_replace("#(^|[\n ])([\w]+?://[^ \"\n\r\t<]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $trans_content); 
   $trans_content = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $trans_content); 
   $trans_content = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $trans_content);	
   return $trans_content;

function php_and_code($stringc, $stringb, $stringe, $stringt){ 

/* $stringc -> string content, $stringb -> string begin, $stringe -> string end, $stringt -> string type */

   // To [php.][/php.]
   if($stringt == 'PHP'){
      $stringb = "<?php"; $stringe = "?>"; 
      $stringc = str_replace("\\\"","\"", $stringc); 
      highlight_string($stringb.'<br />'.$stringc.'<br />'.$stringe); 
      $stringc = ob_get_contents(); 

    // To [code.][/code.]
      $stringc = str_replace("\\\"","\"", $stringc); 
      $stringc = $stringb.'<br />'.$stringc.'<br />'.$stringe;
   return $stringc; 

I don´t believe in the lines marked with '// *' :p
Post reply to report some error. I´m working in this too ;)
Hi gesf do you have an update of the code ;/ the php and code doesnt work to well.

check this out damb LOL
I like that WYSIWYG editor!
Yes, i do have an updated version of the code, however it's too confusing now.
It is mixed with geshi to hilite other languages' code and also works with MathML.
I wish there was a simple one like the one on this forum becouse to many features can confuse people ;/ and get them into trubble. if you or any one can do it might help some people. *using subsilver bbcode javascript