Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
I didn't mean that. <_< I meant the code tags.

egbakaet

egbakaet Avatar

*
New Member

14


November 2005
function bbcode_code ($str)  
{
   $str = str_replace("\n", md5("\n"), $str);
   while (preg_match("/\[code\](.*?)\[\/code\]/", $str, $codesection))  
   {
       $minusbreaks = str_replace('<br />', '', $codesection[0]);
       $str = str_replace($codesection[0], $minusbreaks, $str);  

       $lines = explode(md5("\n"), $codesection[0]);

       $number_lines = count($lines);
       $number_lines = ($number_lines <= 20 ? $number_lines : 20);

       $open = "<center><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"450px\">
<tr>
<td width=\"450px\" align=\"left\" style=\"border-bottom: 1px solid #272d36; padding-bottom: 1px;\">

<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"450px\" bgcolor=\"#666E74\">
<tr>
<td width=\"450px\" align=\"left\" style=\"padding-left:2px;\">
<b>ยป Code:</b>
</tr>
</table>

</tr>

<tr><td style=\"background-repeat: no-repeat; font-size: 7pt; font-family: tahoma; vertical-align: text-top; border-left-style: solid; border-right-style: solid; border-top-style: solid; border-bottom-style: solid; border-left-width: 1px; border-right-width: 1px; border-top-width: 0px; border-bottom-width: 1px; border-left-color: #272d36; border-right-color: #272d36; border-top-color: #272d36; border-bottom-color: #272d36; padding: 2px; margin-bottom: 0px;\" align=\"left\">";  
       $close = "</td></tr></table></center>";  
       $newcodesection = $open . str_replace('<br />', '', $codesection[1]) . $close;
       $str = str_replace($minusbreaks, $newcodesection, $str);
   }
   return(str_replace(md5("\n"), "\n", $str));  
}  


Chris

Chris Avatar

******
Head Coder

19,519


June 2005
Questoin. :P What's codesection in the code?

egbakaet

egbakaet Avatar

*
New Member

14


November 2005
Holds the content of the text between [ code ][ /code ] before it's <br />'s and \n's are removed.

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
I went ahead and made a better parser. I personally think it works quite well, if you want to see it. I made it using completely RegExp, and you can modify it to your needs. :D It could also be used to create "noubbc" tags.



function ubbc($ext){
$ext = preg_replace("/\[code\](.+?)\[(.+?)\[\/code\]/i","[code]$1[$2[/code]",$ext);
$ext = preg_replace("/\[code\]\[(?!\/code)(.+?)\[\/code\]/i","[code][$1[/code]",$ext);
$ext = preg_replace("/\[code\](.+?)\](.+?)\[\/code\]/i","[code]$1]$2[/code]",$ext);
$ext = preg_replace("/\[code\](.+?)(?!\/code)\]\[\/code\]/i","[code]$1][/code]",$ext);
$ext = preg_replace("/\[code\](.+?)\[\/code\]/i","<table border=\"1\"><tr><td>$1</td></tr></table>",$ext);
return $ext;
}


Here is a preview

The inputted info is [code][b]test[/b][/code][b]test2[/b]. Of course, I added a function for bold tags.


Last Edit: Dec 29, 2005 7:26:28 GMT by Chris

egbakaet

egbakaet Avatar

*
New Member

14


November 2005
Here's a more formal example of mine:

Link

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
I admit, your's is truly nice. :P Mine could probably incorporate some of those features if done correctly, but that's not really important.

newBookmarkLockedFalling