Funjoy
Erfahrenes Mitglied
Hallo,
Ich arbeite gerade an einer BB Code Klasse. Ich wollte da mal paar fragen stellen weill ich dafür keine antwort habe
1. Welche methode ist besser bzw. schneller beim parsen. wenn ich für jeden BBCode eine extra preg_replace() funktion nutze oder wenn ich alles in ein Array mache und nur eine preg_replace() funktion nutze!?
2. Ich habe schon ein HTML syntaxhighlighter programmiert nur habe ich das Problem das er bei ca. 100 Codezeilen sehr lange beim parsen brauch ist das normal? Ich habe das so gemacht:
3. Warum wird die funktion preg_replace_callback() so gut wie vermieden gibs da nachteile gegenüber preg_replace()?
So ansonsten war das schon alles hoffe mir kann jemand helfen
MfG Funjoy
Ich arbeite gerade an einer BB Code Klasse. Ich wollte da mal paar fragen stellen weill ich dafür keine antwort habe
1. Welche methode ist besser bzw. schneller beim parsen. wenn ich für jeden BBCode eine extra preg_replace() funktion nutze oder wenn ich alles in ein Array mache und nur eine preg_replace() funktion nutze!?
2. Ich habe schon ein HTML syntaxhighlighter programmiert nur habe ich das Problem das er bei ca. 100 Codezeilen sehr lange beim parsen brauch ist das normal? Ich habe das so gemacht:
PHP:
<?php
function HTML($array)
{
//> Zeilen Zählen.
$Line = explode("\n",trim($array[1]));
for($cLine=1;$cLine<=count($Line);$cLine++)
{
$Lines .= " ".$cLine." <br>";
}
$string = $array[1];
$string = preg_replace("!<br />!","",$string);
$string = preg_replace("!\[!siU","[",$string);
$string = preg_replace("!\]!siU","]",$string);
$string = preg_replace("!\{!siU","{",$string);
$string = preg_replace("!\}!siU","}",$string);
$string = preg_replace("!'!Ui","'",$string);
$string = preg_replace("!\"!Ui",""",$string);
//> Text der in Anführungszeichen Steht Blau ausgeben.
$string = preg_replace_callback("!'(.*)'!siU",array(&$this,"DelColorQuot2"),$string);
$string = preg_replace_callback("!"(.*)"!siU",array(&$this,"DelColorQuot1"),$string);
//> Schlüsselwörter farblich hervorheben.
$string = preg_replace("!&([a-zA-Z0-9#]+);!iU","<em><b>&$1;</b></em>",$string);
$string = preg_replace("!<!siU","<font color=\"#000099\"><",$string);
$string = preg_replace("!>!siU","></font>",$string);
//> Begin Tags einfärben.
$string = preg_replace("!<(script| script)(.*)>!siU","<font color=\"#990000\"><$1$2></font>",$string);
$string = preg_replace("!<( a|a)(.*)>!siU","<font color=\"#009900\"><$1$2></font>",$string);
$string = preg_replace("!<( img|img)(.*)>!siU","<font color=\"#990099\"><$1$2></font>",$string);
$string = preg_replace("!<( style|style)(.*)>!siU","<font color=\"#990099\"><$1$2></font>",$string);
$string = preg_replace("!<( form|form)(.*)>!siU","<font color=\"#FF9900\"><$1$2></font>",$string);
$string = preg_replace("!<( textarea|textarea)(.*)>!siU","<font color=\"#FF9900\"><$1$2></font>",$string);
$string = preg_replace("!<( select|select)(.*)>!siU","<font color=\"#FF9900\"><$1$2></font>",$string);
$string = preg_replace("!<( option|option)(.*)>!siU","<font color=\"#FF9900\"><$1$2></font>",$string);
$string = preg_replace("!<( input|input)(.*)>!siU","<font color=\"#FF9900\"><$1$2></font>",$string);
$string = preg_replace("!<( table|table)(.*)>!siU","<font color=\"#009999\"><$1$2></font>",$string);
$string = preg_replace("!<( th|th)(.*)>!siU","<font color=\"#009999\"><$1$2></font>",$string);
$string = preg_replace("!<( td|td)(.*)>!siU","<font color=\"#009999\"><$1$2></font>",$string);
$string = preg_replace("!<( tr|tr)(.*)>!siU","<font color=\"#009999\"><$1$2></font>",$string);
$string = preg_replace("!<( tbody|tbody)(.*)>!siU","<font color=\"#009999\"><$1$2></font>",$string);
$string = preg_replace("!<( tfoot|tfoot)(.*)>!siU","<font color=\"#009999\"><$1$2></font>",$string);
$string = preg_replace("!<(script| script)(.*)>(.*)<\/script>!siU","<$1$2><font color=\"#0000CC\">$3</font></script>",$string);
//> End Tags Einfärben.
$string = preg_replace("!<\/script>!siU","<font color=\"#990000\"></script></font>",$string);
$string = preg_replace("!<\/a>!siU","<font color=\"#009900\"></a></font>",$string);
$string = preg_replace("!<\/style>!siU","<font color=\"#990099\"></style></font>",$string);
$string = preg_replace("!<\/form>!siU","<font color=\"#FF9900\"></form></font>",$string);
$string = preg_replace("!<\/textarea>!siU","<font color=\"#FF9900\"></textarea></font>",$string);
$string = preg_replace("!<\/select>!siU","<font color=\"#FF9900\"></select></font>",$string);
$string = preg_replace("!<\/option>!siU","<font color=\"#FF9900\"></option></font>",$string);
$string = preg_replace("!<\/table>!siU","<font color=\"#009999\"></table></font>",$string);
$string = preg_replace("!<\/th>!siU","<font color=\"#009999\"></th></font>",$string);
$string = preg_replace("!<\/td>!siU","<font color=\"#009999\"></td></font>",$string);
$string = preg_replace("!<\/tr>!siU","<font color=\"#009999\"></tr></font>",$string);
$string = preg_replace("!<\/tbody>!siU","<font color=\"#009999\"></tbody></font>",$string);
$string = preg_replace("!<\/tfoot>!siU","<font color=\"#009999\"></tfoot></font>",$string);
//> Kommentare Grau ausgeben.
$string = preg_replace_callback("!<\!--(.*)-->!siU",array(&$this,"DelColor2"),$string);
//> CSS Farblich hervorheben.
$string = preg_replace_callback("!<font color=\"#000099\"><font color=\"#990099\"><style type=<font color=\"#0000ff\">\"text/css\"</font>></font></font>(.*)<font color=\"#000099\"><font color=\"#990099\"></style></font></font>!siU",array(&$this,"CSS"),$string);
$Code = nl2br($string);
//> Hier könnt ihr den Header und Footer für HTML editieren.
$Header = "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"".$this->Code_TableWidth."\"><tr><td width=\"".$this->Code_TableWidth."\" valgin=\"top\">"
."<div style=\"overflow: auto; height: ".(37+(count($Line)*16))."; width: 100%;\">"
."<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"BORDER: 1px SOLID ".$this->Code_BGColor1.";\" width=\"100%\">"
."<tr><td colspan=\"3\" style=\"FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;FONT-SIZE:13px;FONT-WEIGHT:BOLD;COLOR:".$this->Code_FontColor.";BACKGROUND-COLOR:".$this->Code_BGColor1.";\"> HTML-Code</td></tr>"
."<tr bgcolor=\"".$this->Code_BGColor2."\"><td style=\"COLOR:".$this->Code_FontColor.";BACKGROUND-COLOR:".$this->Code_BGColor1.";\" align=\"center\" width=\"20\" valign=\"top\"><code>"
.$Lines
."</code></td><td width=\"5\"> </td><td valign=\"top\" nowrap><code>";
$Footer = "</code></td></tr></table></div></td></tr></table>";
return $Header.trim($Code).$Footer;
}
?>
3. Warum wird die funktion preg_replace_callback() so gut wie vermieden gibs da nachteile gegenüber preg_replace()?
So ansonsten war das schon alles hoffe mir kann jemand helfen
MfG Funjoy