This is how you do it. This code is minimal, there are some sercurity issues you need to deal with. but, run this and you will get the idea.
<style>
.code {
border-width: 1px;
border-style: inset;
padding: 8px;
background-color: #FFFFDD;
}
.quote {
border-width: 1px;
border-style: inset;
padding: 8px;
background-color: #DDDDFF;
}
.link {
border-width: 1px;
border-style: inset;
padding: 8px;
background-color: #DDFFDD;
}
</style>
<?php
function ExtractTag($haystack, $tag, &$start, &$middle, &$end)
{
$k = strlen($tag) + 2;
if(($i = strpos($haystack, "[$tag]")) !== false)
{
$j = strpos($haystack, "[/$tag]", $i);
if($j === false) $j = strlen($s);
$start = substr($haystack, 0, $i);
$middle = trim(substr($haystack, $i + $k, ($j - $i) - $k));
$end = substr($haystack, $j + $k + 1);
return true;
}
return false;
}
function EncodeCode($s)
{
return "Code:<div class=code>" . highlight_string($s, true) . "</div>";
}
function EncodeQuote($s)
{
return "Quote:<div class=quote>" . nl2br($s) . "</div>";
}
function EncodeLink($s)
{
return "Link:<div class=link><a href='$s'>$s</a></div>";
}
function EncodeText($s)
{
return "<div class=text>" . nl2br($s) . "</div>";
}
function EncodePost($s)
{
if(ExtractTag($s, "code", $start, $middle, $end))
$s = EncodePost($start) . EncodeCode($middle) . EncodePost($end);
else
if(ExtractTag($s, "quote", $start, $middle, $end))
$s = EncodePost($start) . EncodeQuote($middle) . EncodePost($end);
else
if(ExtractTag($s, "link", $start, $middle, $end))
$s = EncodePost($start) . EncodeLink($middle) . EncodePost($end);
else
$s = EncodeText($s);
return $s;
}
echo EncodePost("This is my post
[code]
<?php
echo \"my code\";
?>
Hello, this is more of my post and here is a quote,
Man who stand on toilet is high on pot
[link]http://www.buzzphp.com[/link]");
?>[/code]