note 27793 deleted from function.highlight-file by aidan
| From: | aidan@php.net | Date: | Sun, 26 Sep 2004 13:57:32 +0000 |
| Subject: | note 27793 deleted from function.highlight-file by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77382@lists.php.net to get a copy of this message | ||
Note Submitter: tom dot pike at xiven.NO_SPAM.com
----
The following code will reformat the output from the highlight_file function into valid XHTML
(removes <font> elements, replaces with <span>). It also makes use of the <pre>
tag instead of all those and <br /> tags being in there. Hope this helps.
<style type="text/css">
.source span.html { color: <?=ini_get('highlight.html')>; }
.source span.default { color: <?=ini_get('highlight.default')?>; }
.source span.keyword { color: <?=ini_get('highlight.keyword')?>; }
.source span.string { color: <?=ini_get('highlight.string')?>; }
.source span.comment { color: <?=ini_get('highlight.comment')?> }
</style>
<?php
echo '<pre class="source">';
$source = highlight_file('xxx.php', true);
$search[0] = '<font
color="'.ini_get('highlight.html').'">';
$search[1] = '<font
color="'.ini_get('highlight.default').'">';
$search[2] = '<font
color="'.ini_get('highlight.keyword').'">';
$search[3] = '<font
color="'.ini_get('highlight.string').'">';
$search[4] = '<font
color="'.ini_get('highlight.comment').'">';
$search[5] = '</font>';
$search[6] = '<br />';
$search[7] = '\r';
$search[8] = ' ';
$replace[0] = '<span class="html">';
$replace[1] = '<span class="default">';
$replace[2] = '<span class="keyword">';
$replace[3] = '<span class="string">';
$replace[4] = '<span class="comment">';
$replace[5] = '</span>';
$replace[6] = "\n";
$replace[7] = '';
$replace[8] = ' ';
echo str_replace($search,$replace,$source);
echo '</pre>';
?>