Hi,
i have a small class that parse my BB codes but i got a problem with the [php ] because i use GeSHi for highlighting my code ..
so how i can use nl2br for whole text expect what inside the [php ] ...
now i can parse my php codes but this code <? echo 'TEST " inside" '; ?>
display like this <? echo 'TEST \" inside\" '; ?>
this is my class :
<?php
class Parser
{
var $allowHTML = 0;
var $allowBBCode = 1;
var $doAutoBR = 1;
var $parseURL = 0;
function Parser()
{
}
function do_parse($text,$html = 0,$doAutoBR = 0)
{
if ( trim($text) != "")
{
if ($html == 0)
{
$text = $this->convert_tag($text);
}
$text = $this->parseURL == 1 ? $this->parse_links($text) : $text;
if( $doAutoBR == 0 ){
$text = $this->doAutoBR == 1 ? nl2br($text):$text;
}
$text = $this->allowBBCode == 1 ? $this->exec_parse($text) : $text;
}
return $text;
}
function convert_tag($text)
{
$text = str_replace("<","&lt;",$text);
$text = str_replace(">","&gt;",$text);
$text = str_replace("<","<",$text);
$text = str_replace(">",">",$text);
return $text;
}
// Some functions Here .. .
function parse_php($text)
{
$text = str_replace("<br />", "", $text);
$text = str_replace("<","<",$text);
$text = str_replace(">",">",$text);
include_once('geshi/geshi.php');
$source = $text;
$language = 'php';
$geshi =& new GeSHi($source, $language);
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
$code = $geshi->parse_code();
return "<div class=\"phpbox\">".$code."</div>";
}
function parse_links($text)
{
// parse links script
}
function exec_parse($text)
{
$text = preg_replace("/(\[(php)\])([^\\4\\1]*)(\[\/\\2\])/eiUs","\$this->parse_php('\\3')",$text);
$text = preg_replace("/(\[(code)\])([^\\4\\1]*)(\[\/\\2\])/eiUs","\$this->parse_code('\\3')",$text);
$text = preg_replace("/(\[)(code)(=)(['\"]?)([^\"']*)(\\4])(.*)(\[\/code\])/eiUs","\$this->parse_code('\\7','\\5')",$text);
$text = preg_replace("/(\[(HTML)\])([^\\4\\1]*)(\[\/\\2\])/eiUs","\$this->parse_html('\\3')",$text);
return $text;
}
}
?>
thanks in advance for any who want's to help 🙂 ..