Highlight_String()

Mirko D

Erfahrenes Mitglied
Hallo! Hab schon lange keine Frage mehr gehabt, nun ist es heut mal wieder soweit.

Ich hab mir ein Script aus dem Netz gezogen, welches genauso funktioniert wie hier. Also wenn ich hier [ php] und [/ php] eintippe dann kann ich ja damit das Syntaxhighlighting aktivieren.

So jetzt nun die Frage. Wie kann ich dies auf mein script anwenden. Ich hab noch nie mit RegEx gearbeitet, aber irgendwann ist ja bekanntlich immer das erste mal. Also das Script an sich anzuwenden ist ja kein Problem, nur dieses Syntaxhighlighting mittels [phpf]->highlight_string[/phpf] will nicht so ganz.

Es sollte genauso funktionieren wie hier

PHP:
$Vari = " Dies ist ein String"; 
echo $Vari;

Hier mal das Script:


PHP:
function upbcode($text) {
	if(substr_count($text,"[") > 0 && substr_count($text,"]") > 0) {
		$text = preg_replace("#\[color=(\#[0-9a-f]{6}|[a-z]+)\](.*?)\[/color\]#si",'<font color="\1">\2</font>',$text);
		$text = preg_replace("#\[u\](.*?)\[/u\]#si",'<u>\1</u>',$text);
		$text = preg_replace("#\[code\](.*?)\[/code\]#si",'<code>\1</code>',$text);
		$text = preg_replace("#\[s\](.*?)\[/s\]#si",'<s>\1</s>',$text);
		$text = preg_replace("#\[i\](.*?)\[/i\]#si",'<i>\1</i>',$text);
		$text = preg_replace("#\[b\](.*?)\[/b\]#si",'<b>\1</b>',$text);
		$text = preg_replace("#\[center\](.*?)\[/center\]#si",'<center>\1</center>',$text);
		$text = preg_replace("#\[marquee\](.*?)\[/marquee\]#si",'<marquee>\1</marquee>',$text);
                $text = preg_replace("#\[php\](.*?)\[/php\]#si",'&lt;? \1 ?&gt;',$text);
		$text = preg_replace("#\[url\]([a-z]+?://)([^\[]*)\[/url\]#si",'<a href="\1\2" target="_blank">\1\2</a>',$text);
		$text = preg_replace("#\[url\]([^\[]*)\[/url\]#si",'<a href="http://\1" target="_blank">\1</a>',$text);
		$text = preg_replace("#\[url=([a-z]+?://)([^\]]*)\](.*?)\[/url\]#si",'<a href="\1\2" target="_blank">\3</a>',$text);
		$text = preg_replace("#\[url=([^\]]*)\](.*?)\[/url\]#si",'<a href="http://\1" target="_blank">\2</a>',$text);
		$text = preg_replace("#\[email\]([^\[]+@[^\[]+)\[/email\]#si",'<a href="mailto:\1">\1</a>',$text);
		$text = preg_replace('=\[img\](http:[^\[]*|[^\[:]*)\[/img\]=si','<img src="$1" border="0">',$text);
		do {
			$text = preg_replace("#\[quote\](.*?)\[/quote\]#siU",'<center><table border="0" cellspacing="0" cellpadding="0" width="85%"><tr><td><span class="small"><b>Zitat:</b></span><hr noshade><center><table border="0" cellspacing="0" cellpadding="0" width="95%"><tr><td><span class="quote">\1</span></td></tr></table></center><hr noshade></td></tr></table></center>',$text);
		} while(preg_match("#\[quote\](.*?)\[/quote\]#siU",$text));
	}
	return $text;
}

Hoffe das ist nicht zu viel

Gruß Mirko
 
habs mittlwerile heraus bekommen nun hab ich aber das Problem , das er mir alles in Rot einfärbt und nicht im gewünschten Syntaxschema.

Gruß Mirko
 
Zurück