Fonction PHP highlight_string()
Exemple
Sortez une chaîne avec la syntaxe PHP en surbrillance :
<html>
<body>
<?php
highlight_string("Hello world! <?php phpinfo(); ?>");
?>
</body>
</html>
La sortie du navigateur du code ci-dessus sera :
Hello world! <?php phpinfo(); ?>
La sortie HTML du code ci-dessus sera (Afficher la source) :
<html>
<body>
<code>
<span style="color: #000000">Hello world!
<span style="color: #0000BB"><?php phpinfo</span>
<span style="color: #007700">(); </span>
<span style="color: #0000BB">?></span>
</span>
</code>
</body>
</html>
Définition et utilisation
La fonction highlight_string() génère une chaîne avec la syntaxe PHP en surbrillance. La chaîne est mise en surbrillance à l'aide de balises HTML.
Les couleurs utilisées pour la coloration syntaxique peuvent être définies dans le fichier php.ini ou avec la fonction ini_set().
Syntaxe
highlight_string(string,return)
Valeurs des paramètres
Parameter | Description |
---|---|
string | Required. Specifies the string to be highlighted |
return | Optional. If set to TRUE, this function will return the highlighted code as a string, instead of printing it out. Default is FALSE |
Détails techniques
Valeur de retour : | Renvoie TRUE en cas de succès ou FALSE en cas d'échec |
---|---|
Version PHP : | 4+ |
Journal des modifications : | Le paramètre de retour a été ajouté en PHP 4.2.0 |
❮ Référence Divers PHP