Accès au manager - réservé aux membres

Navigation

Bouts de Codes PHP

Colorisation de code php valide xhtml

Informations sur le code source PHP

Ecrit par :  TommyWeb
Site de l'auteur Voir
Autres codes en PHP de l'auteur : [2] sources Voir
Date d'enregistrement du code le 03 Mars 2006 - Vu 3822 fois
Code source zippé: Télécharger le fichier ZIP
Impression: Imprimer le code
Ajouter la page à vos favoris

Description du code source

Informations sur le code source

Ceci est un morceau de code qui va rendre un code php en couleur et tout cela valide en xhtml !

Code Source



.01
.02
.03
.04
.05
.06
.07
.08
.09
.10
.11
.12
.13
.14
.15
.16
.17
.18
.19
.20
.21
.22
.23
.24
.25
.26
.27
.28
.29
.30
.31
.32
.33
.34
.35
.36
.37
.38
.39
.40
.41
.42
.43
.44
.45
.46
.47
.48
.49
.50
.51
.52
.53
.54
.55
.56
.57
 

<?php
/******************************************************************************/
/*                                                                            */
/*                       __        ____                                       */
/*                 ___  / /  ___  / __/__  __ _____________ ___               */
/*                / _ \/ _ \/ _ \_\ \/ _ \/ // / __/ __/ -_|_-<               */
/*               / .__/_//_/ .__/___/\___/\_,_/_/  \__/\__/___/               */
/*              /_/       /_/                                                 */
/*                                                                            */
/*                                                                            */
/******************************************************************************/
/*                                                                            */
/* Titre          : Colorisation de code php valide xhtml                     */
/*                                                                            */
/* URL            : http://www.phpsources.org/scripts165-PHP.htm              */
/* Auteur         : TommyWeb                                                  */
/* Date édition   : 03 Mars 2006                                              */
/* Website auteur : http://www.tommyweb.org                                   */
/*                                                                            */
/******************************************************************************/

function colorisationphp($string)
{
    $string highlight_string($stringtrue);
                
    $in = array(
        '`<(?:font color="|span style="color: )'.
        ini_get('highlight.html').'">(.+?)</(?:font|span)>`si',
        '`<(?:font color="|span style="color: )'.
        ini_get('highlight.comment').'">(.+?)</(?:font|span)>`si',
        '`<(?:font color="|span style="color: )'.
        ini_get('highlight.default').'">(.+?)</(?:font|span)>`si',
        '`<(?:font color="|span style="color: )'.
        ini_get('highlight.keyword').'">(.+?)</(?:font|span)>`si',
        '`<(?:font color="|span style="color: )'.
        ini_get('highlight.string').'">(.+?)</(?:font|span)>`si',
        '`</(?:font|span)>`si'
    ); 
                    
    $out = array(
        '<span style="color: '.
        ini_get('highlight.html').'">$1</span>',
        '<span style="color: '.
        ini_get('highlight.comment').'">$1</span>',
        '<span style="color: '.
        ini_get('highlight.default').'">$1</span>',
        '<span style="color: '.
        ini_get('highlight.keyword').'">$1</span>',
        '<span style="color: '.
        ini_get('highlight.string').'">$1</span>',
        '</span>'
    );
                    
    return preg_replace($in$out$string);
}
?> 

Fonctions du code source

Fonctions php / mysql PHP

  • highlight_string : Applique la syntaxe colorisée à du code PHP - (PHP 4, PHP 5)
  • array : Crée un tableau - (PHP 4, PHP 5)
  • ini_get : Lit la valeur d'une option de configuration - (PHP 4, PHP 5)
  • preg_replace : Rechercher et remplacer par expression rationnelle standard - (PHP 4, PHP 5)

Commentaires [2]

dothazard
le 18/03/2007 à 13:30:00
Comment l'utiliser?
KOogar
le 18/03/2007 à 16:37:00
Comme n'importe quel autre fonction :

echo colorisationphp($string);

Poster un commentaire

:P :) :wink: :lol: :surprised: :confused: :mad: :no:
Taille du texte:
Couleur:
Code de sécurité

Les dernières offres d'emploi