Listing du fichier montresource.php avec syntaxhighlighter
<?php # # (gH) -_- montresource.php ; TimeStamp (unix) : 25 Février 2026 vers 11:03 error_reporting(E_ALL | E_NOTICE ) ; include("std.php") ; ############################################################ 1 # # pour des raisons de sécurité, il ne faut pas mettre # ce programme à la racine de votre site ou dans un # répertoire qui permettrait de voir des fichiers "sensibles" # (avec mot de passe, option de configuration...) # ############################################################ 2 debutPage("Code-source ","strict") ; debutSection("100%") ; $aide = "oui" ; $txtaide = "Pour ne pas avoir les numéros de ligne, ajouter &nl=non à l'URL." ; $txtaide = "" ; # sans paramètre, on affiche l'aide if (isset($_GET["nomfic"])) { $fn = $_GET["nomfic"] ; $aide = "non" ; } ; # finsi # affichage éventuel de l'aide if ($aide=="oui") { h2("Syntaxe : montresource.php?nomfic=".s_span("nom du fichier","gbleuf")) ; pvide() ; h3("Exemples :") ; blockquote() ; p() ; echo "- avec numéros de ligne : " ; echo href("montresource.php?nomfic=std.php","std.php") ; nbsp(5) ; echo href("montresource.php?nomfic=std.css","std.css") ; finp() ; p() ; echo "- sans numéros de ligne : " ; echo href("montresource.php?nomfic=std.php&nl=non","std.php&nl=non") ; finp() ; finblockquote() ; finSection() ; finPage() ; return ; } ; # fin si # il faut vérifier qu'on ne remonte pas avec le nom du fichier $li = 1 ; $nl = "" ; if (isset($_GET["nl"])) { $nl = $_GET["nl"] ; } ; if ($nl=="non") { $li = 0 ; } ; $strp = strpos(" $fn","..") ; $strc = strpos(" $fn","./") ; $strr = strpos(" $fn","/") ; $strh = strpos(" $fn","http") ; if (($strp) or ($strh) or ($strc) or ($strr) ) { echo "Non ! La remontée avec .. ou http://... ou / est interdite." ; finSection() ; finPage() ; return ; } ; # fin si # puis il faut vérifier que le fichier existe if (!file_exists($fn)) { h1("Fichier ".b("$fn")." introuvable.") ; finSection() ; finPage() ; return ; } ; # fin si # arrivé ici, on peut afficher... $server = $_SERVER['SERVER_NAME'] ; h1("Listing du fichier $fn ") ; pvide() ; sdl() ; cmt($txtaide) ; sdl() ; $typeFic = substr($fn,strrpos($fn,".")) ; echo "\n<!-- listing de $fn mode numéro de ligne = $li -->\n\n" ; div() ; /* inutile, suite au changement de version if ($server == "localhost") { } else { echo showSourcePhpLeria($fn,$typeFic,$li) ; } ; # fin si */ echo showSourcePhpGh($fn,$typeFic,$li) ; findiv() ; echo "<!-- fin du listing de $fn -->\n\n" ; p("texte") ; echo " Pour ne pas voir les numéros de ligne, ajoutez ".b("&nl=non")." à la suite du nom du fichier. " ; finp() ; ############################################################ function showSourcePhpGh($chemin,$typeFic="txt",$nbLigne = 1) { ############################################################ if (file_exists($chemin)) { $str = highlight_file($chemin, TRUE); } else { return "Fichier ".b("$chemin")." introuvable." ; } ; # fin si // Nettoyage du code $str = str_replace("<code>", '', $str) ; $str = str_replace("</code>", '', $str) ; $str = str_replace("<pre>", '', $str) ; $str = str_replace("</pre>", '', $str) ; $str = preg_replace('/<span style="(.*)">(.*)<(.*)<\/span>/Um','<span style="\1">\2</span><\3',$str); $out = $str ; // Explode sur le <br /> $str = str_replace("\n", '<br />', $str); $arr = explode('<br />', $str); $nbe = count($arr) ; if ($nbe==1) { $arr = explode('\n', $str); $nbe = count($arr) ; } ; # fin si $numLigne = 0 ; $out = "" ; foreach ($arr as $ligne){ #$ligne = str_replace("\n", '', $ligne); #$ligne = str_replace("\r", '', $ligne); $numLigne++ ; if ($numLigne<$nbe) { if ($nbLigne==1) { $out .= '<span style="color:#000000">'.sprintf("%05d ",$numLigne)."</span>".snbsp(4) ; } ; # fin si $out .= $ligne ; $out .= " <br />\n"; } else { $out .= "</span>\n" ; } ; # fin si on n'est pas à la dernière ligne } ; # fin pour chaque $out = "<code>\n".$out."</code>\n"; return $out; } # fin de fonction showSourcePhpGh ############################################################ function showSourcePhpLeria($chemin,$typeFic="txt",$nbLigne = 1) { ############################################################ if (file_exists($chemin)) { $str = highlight_file($chemin, TRUE); } else { return "Fichier ".b("$chemin")." introuvable." ; } ; # fin si // Nettoyage du code $str = str_replace("<code>", '', $str) ; $str = str_replace("</code>", '', $str) ; $str = preg_replace('/<span style="(.*)">(.*)<(.*)<\/span>/Um','<span style="\1">\2</span><\3',$str); // Explode sur le <br /> $arr = explode('<br />', $str); $numLigne = 0 ; $nbe = count($arr) ; $out = "" ; foreach ($arr as $ligne){ $ligne = str_replace("\n", '', $ligne); $numLigne++ ; if ($numLigne<$nbe) { if ($nbLigne==1) { $out .= '<span style="color:#000000">'.sprintf("%05d ",$numLigne)."</span>".snbsp(4) ; } ; # fin si $out .= $ligne." <br />\n"; } else { $out .= "</span>\n" ; } ; # fin si on n'est pas à la dernière ligne } ; # fin pour chaque $out = "<code>\n".$out."</code>\n"; return $out; } # fin de fonction showSourcePhpLeria finSection() ; finPage() ; ?>La coloration syntaxique est réalisée par : SyntaxHighlighter.
Si vous préférez, vous pouvez utiliser celle de geshi ou même celle construite autour de la fonction highlight_file.
Retour à la page principale de (gH)