note 93268 added to function.highlight-file
| From: | MikiRoro at osu1 dot php dot net | Date: | Mon, 31 Aug 2009 15:39:20 +0000 |
| Subject: | note 93268 added to function.highlight-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-160089@lists.php.net to get a copy of this message | ||
highlight_file() wraps HTML tags around PHP constructions,
so it's not useful for CLI. If you want to have highlighted source
in command line, use this script:
<?php
$php = $argv[1]; // set a path
if(!$php)
$php = $argv[0];
$c_string = ini_get('highligth.string'); // get ini values
$c_comment = ini_get('highlight.comment');
$c_keyword = ini_get('highlight.keyword');
$c_default = ini_get('highlight.default');
$c_html = ini_get('highlight.html');
$source = highlight_file($php, true); // load highlighted source
$source = str_replace('</span>', '[0m', $source); // replace html tags
$source = str_replace('<span style="color: #DD0000">', '[32m',
$source);
$source = str_replace('<span style="color: '.$c_comment.'">',
'[37m', $source);
$source = str_replace('<span style="color: '.$c_keyword.'">',
'[34m', $source);
$source = str_replace('<span style="color: '.$c_default.'">',
'[31m', $source);
$source = str_replace('<span style="color: '.$c_html.'">',
'[30m', $source);
$source = str_replace('<code>', '', $source); // strip <code> and
<br>
$source = str_replace('</code>', '', $source);
$source = str_replace('<br />', "\n", $source);
$source = str_replace(' ', ' ', $source); // remove   and
entities
$source = html_entity_decode($source);
echo $source;
?>
Then type
php highlight.php some_other_script.php to have
colorful source in terminal window. Tested under Ubuntu.
----
Server IP: 194.24.174.37
Probable Submitter: 79.163.130.132
----
Manual Page -- http://www.php.net/manual/en/function.highlight-file.php
Edit -- https://master.php.net/note/edit/93268
Del: integrated -- https://master.php.net/note/delete/93268/integrated
Del: useless -- https://master.php.net/note/delete/93268/useless
Del: bad code -- https://master.php.net/note/delete/93268/bad+code
Del: spam -- https://master.php.net/note/delete/93268/spam
Del: non-english -- https://master.php.net/note/delete/93268/non-english
Del: in docs -- https://master.php.net/note/delete/93268/in+docs
Del: other reasons-- https://master.php.net/note/delete/93268
Reject -- https://master.php.net/note/reject/93268
Search -- https://master.php.net/manage/user-notes.php