highlight_file

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">&lt;?<br /><br /></span><span style="color: #FF8000">//&nbsp;comment<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">myfunction</span><span style="color: #007700">()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$myvariable&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Hello"</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</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">?&gt;</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">&lt;?<br /><br /></span><span style="color: #FF8000">//&nbsp;comment<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">myfunction</span><span style="color: #007700">()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$myvariable&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Hello"</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</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">?&gt;</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">&lt;?<br /><br /></span><span style="color: #ffff00">//&nbsp;comment<br /></span><span style="color: #00ff00">function&nbsp;</span><span style="color: #0000ff">myfunction</span><span style="color: #00ff00">()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">$myvariable&nbsp;</span><span style="color: #00ff00">=&nbsp;</span><span style="color: #ff0000">"Hello"</span><span style="color: #00ff00">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</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">?&gt;</span>
</span>
</code>

__halt_compiler

connection_aborted

connection_status

constant

define

defined

die

eval

exit

highlight_string

hrtime

ignore_user_abort

pack

php_strip_whitespace

show_source

sleep

sys_getloadavg

time_nanosleep

time_sleep_until

uniqid

unpack

usleep

PHP

Home Menu