highlight_file
Description
Syntax highlighting of a file
Syntax
highlight_file ( string $filename [, bool $return = FALSE ] ) : mixed
Parameters
filename
Path to the PHP file to be highlighted.
return
Set this parameter to TRUE to make this function return the highlighted code.
Return
If return is set to TRUE, returns the highlighted code as a string instead of printing it out. Otherwise, it will return TRUE on success, FALSE on failure.
Examples
1 · filename
<? $filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/highlight_file.txt'; highlight_file($filename); ?>
<code><span style="color: #000000"> <span style="color: #0000BB"><?<br /><br /></span><span style="color: #FF8000">// comment<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">myfunction</span><span style="color: #007700">()<br />{<br /> </span><span style="color: #0000BB">$myvariable </span><span style="color: #007700">= </span><span style="color: #DD0000">"Hello"</span><span style="color: #007700">;<br /><br /> echo </span><span style="color: #0000BB">$myvariable</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">myfunction</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?></span> </span> </code>
2 · return
<? $filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/highlight_file.txt'; $return = true; $result = highlight_file($filename, $return); echo $result; ?>
<code><span style="color: #000000"> <span style="color: #0000BB"><?<br /><br /></span><span style="color: #FF8000">// comment<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">myfunction</span><span style="color: #007700">()<br />{<br /> </span><span style="color: #0000BB">$myvariable </span><span style="color: #007700">= </span><span style="color: #DD0000">"Hello"</span><span style="color: #007700">;<br /><br /> echo </span><span style="color: #0000BB">$myvariable</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">myfunction</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?></span> </span> </code>
3 · ini_set
<? ini_set('highlight.comment', '#ffff00'); ini_set('highlight.default', '#0000ff'); ini_set('highlight.html', '#000000'); ini_set('highlight.keyword', '#00ff00'); ini_set('highlight.string', '#ff0000'); $filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/highlight_file.txt'; highlight_file($filename); ?>
<code><span style="color: #000000"> <span style="color: #0000ff"><?<br /><br /></span><span style="color: #ffff00">// comment<br /></span><span style="color: #00ff00">function </span><span style="color: #0000ff">myfunction</span><span style="color: #00ff00">()<br />{<br /> </span><span style="color: #0000ff">$myvariable </span><span style="color: #00ff00">= </span><span style="color: #ff0000">"Hello"</span><span style="color: #00ff00">;<br /><br /> echo </span><span style="color: #0000ff">$myvariable</span><span style="color: #00ff00">;<br />}<br /><br /></span><span style="color: #0000ff">myfunction</span><span style="color: #00ff00">();<br /><br /></span><span style="color: #0000ff">?></span> </span> </code>