Hallo;
Ik heb hier via jullie site een scriptje gevonden om php te highlighten.
Ik heb dit gebruikt maar ik ben nu van plan dit ook voor javascript te gebruiken (zodat daar ook vanalles een kleurtje krijgt)
dit heb ik er ongeveer van gemaakt:
<?php
function highlight($code) {
// functie om javascript en html ook te highlighten:
//html opzetten (zodat je < en > ziet)
$code = str_replace("<", "<", $code);
$code = str_replace(">", ">", $code);
// geschreven phptags naar ascii zetten:
$code = preg_replace("#<\?php|<\?PHP|<\?#", "HIERBEGINPHPCODEdiewordomgezetsecretword", $code);
$code = str_replace("?>", "HIEREINDEPHPCODEdiewerdomgezetsecretword", $code);
//zorgen dat het highlighten niet stopt bij </script>
$code = str_replace("</script>", "</script><?php", $code);
$code = "<?php".$code."?>";
$source = highlight_string($code, true);
$source = explode('<br />',$source);
for ($i = 0; $i < count($source); $i++) {
$source[$i] = "<tr><td><code><font color='black'>".($i + 1)."</font></td><td width='100%'>".$source[$i];
}
$source = implode('</code></td></tr>',$source);
// zorgen dat alles juist word weergegeven
$source = preg_replace("#\<\?php#", "", $source);
$source = str_replace("?>", "", $source);
$source = str_replace("HIERBEGINPHPCODEdiewordomgezetsecretword", "<font color='#000000'><font color='#0000BB'><?php</font>", $source);
$source = str_replace("HIEREINDEPHPCODEdiewerdomgezetsecretword", "<font color='#000000'><font color='#0000BB'>?></font>", $source);
$bron = "<br /><table align='center' bgcolor='lightgray' bordercolor='#00CC00' width='75% border='1' cellspacing='0' cellpadding='0''>".$source."</table><br />";
return $bron;
}
?>
maar nu is het probleem:
er worden woorden/functies/haken niet omgezet in kleuren, weet iemand hoe dit komt en weet er misschien ook iemand hoe ik dit script beter kan maken??
hier even de link naar een voorbeeldje: http://veewee.depas.be/testje.php
Dank!
531 views