PHP highlight_string() Functie
Voorbeeld
Voer een string uit met de PHP-syntaxis gemarkeerd:
<html>
<body>
<?php
highlight_string("Hello world! <?php phpinfo(); ?>");
?>
</body>
</html>
De browseruitvoer van de bovenstaande code is:
Hello world! <?php phpinfo(); ?>
De HTML-uitvoer van de bovenstaande code is (Bron weergeven):
<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>
Definitie en gebruik
De functie highlight_string() voert een string uit met de PHP-syntaxis gemarkeerd. De tekenreeks wordt gemarkeerd met behulp van HTML-tags.
De kleuren die worden gebruikt voor syntaxisaccentuering kunnen worden ingesteld in het php.ini-bestand of met de ini_set()-functie.
Syntaxis
highlight_string(string,return)
Parameterwaarden
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 |
Technische details
Winstwaarde: | Retourneert TRUE bij succes of ONWAAR bij mislukking |
---|---|
PHP-versie: | 4+ |
Wijzigingslogboek: | De return -parameter is toegevoegd in PHP 4.2.0 |
❮ PHP overige referentie