Hello;
I have a suggestion for output from highlight_file(<file>, true);
I am trying to format the string for display in <pre> tags:
if((file_exists('php/runner.php') && $_done) || $_show)
{
print "<pre class=\"norm\">\n".$_showStr."</pre>\n";
$_lines = highlight_file('php/runner.php', true);
$_lines = str_replace("<code>", "<code>\n", $_lines);
$_lines = str_replace(" ", " ", $_lines);
$_lines = str_replace("<br /></span>", "</span><br />", $_lines);
$_linesRed = explode("\n", $_lines);
$_lineNum = explode('<br />', $_linesRed[2]);
$_display = $_linesRed[0].$_linesRed[1]."\n";
for($_itr = 0; $_itr < count($_lineNum); $_itr++)
{
$_display .= $_itr." ".$_lineNum[$_itr]."\n";
}
$_display .= $_linesRed[3].$_linesRed[4];
print "\n<pre>\n".$_display."</pre>\n";
}
which produces (browser view source )
I have to include a unix formated plain text file
because the e-mail client will not preserver the formatting
so you can see what I am talking about:
<pre>
<code><span style="color: #000000">
0 <span style="color: #0000BB"><?php
1 </span>
2 <span style="color: #FF8000">// addScript -></span>
3 <span style="color: #007700">function </span><span style="color: #0000BB">runner</span><span style="color: #007700">()
4 {
5 </span><span style="color: #0000BB">$_fr </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'js/lab_0.js'</span><span style="color: #007700">, </span><span style="color: #DD0000">'r'</span><span style="color: #007700">);
6 </span><span style="color: #0000BB">$_js </span><span style="color: #007700">= </span><span style="color: #0000BB">fread</span><span style="color: #007700">(</span><span style="color: #0000BB">$_fr</span><span style="color: #007700">, </span><span style="color: #0000BB">filesize</span><span style="color: #007700">(</span><span style="color: #DD0000">'js/lab_0.js'</span><span style="color: #007700">));
7 </span><span style="color: #0000BB">$_js </span><span style="color: #007700">= </span><span style="color: #0000BB">str_replace</span><span style="color: #007700">(</span><span style="color: #DD0000">"alert(\"Hello from lab_0.js\")"</span><span style="color: #007700">, </span><span style="color: #DD0000">""</span><span style="color: #007700">, </span><span style="color: #0000BB">$_js</span><span style="color: #007700">);
8 </span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$_fr</span><span style="color: #007700">);
9 </span><span style="color: #0000BB">$_fw </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'js/lab_0.js'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w'</span><span style="color: #007700">);
10 </span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$_fw</span><span style="color: #007700">, </span><span style="color: #0000BB">$_js</span><span style="color: #007700">);
11 </span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$_fw</span><span style="color: #007700">);
12 return </span><span style="color: #0000BB">0</span><span style="color: #007700">;
13 }
14
15
16
17
18
19 </span>
20 <span style="color: #0000BB">?></span>
</span></code></pre>
There are places where there may be a variable number of spaces before
a closing </span>
so the line numbers end up with the style from the previous <span>
tag, and the str_replace
line; $_lines = str_replace("<br /></span>", "</span><br />",
$_lines); that moves the <br />
tags to follow </span> and precede the next <span> tag won't find
instances where there are
spaces without a regex to match spaces in this context.
In the file you will see each line after the first { begin with </span>
The suggestion is to have developers revise algorythm used by
highlight_file to place <br />
tags between </span> and <span> tags wherever possible. Or even
provide the option to
return string for use between <pre> tags.
I am experimenting with a web interface that writes code to a file and
then is able to view/edit/execute it.
Since it is written to a php code file, eval() is not necessary.
I have no plans to deploy this in a public accessible site.
Thank you for time and attention.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php