note 110843 modified in function.highlight-file by danbrown
| From: | danbrown@php.net | Date: | Thu, 13 Dec 2012 20:25:45 +0000 |
| Subject: | note 110843 modified in function.highlight-file by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192521@lists.php.net to get a copy of this message | ||
My custom function for displaying lines:
<?php
function highlight_linesfile($filename, $return = false) {
if(file_exists($filename) && is_file($filename)) {
$output = '<pre><code><span style="color:
'.ini_get('highlight.html').';">';
$code = substr(highlight_file($filename, true), 36, -15);
$start_line = 1;
$lines = explode('<br />', $code);
$chr_lines = count($lines);
$chr_lines = strlen($chr_lines);
foreach($lines as $line)
{
$nline = str_pad($start_line, $chr_lines, ' ', STR_PAD_LEFT);
$output .= '<span style="color: grey;"
class="php_highlight_line">'.$nline. ':</span> '.$line;
$start_line ++;
}
$output .= '</span></code></pre>';
if($return === true) return $return;
else echo $output;
}
}
?>
use this [CSS] to disable selection of lines:
.php_highlight_line {
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
--was--
My custom function for displaying lines:
function highlight_linesfile($filename, $return = false) {
if(file_exists($filename) && is_file($filename)) {
$output = '<pre><code><span style="color:
'.ini_get('highlight.html').';">';
$code = substr(highlight_file($filename, true), 36, -15); //Thanks to this post: http://php.net/manual/en/function.highlight-file.php#92160
$start_line = 1;
$lines = explode('<br />', $code);
$chr_lines = count($lines);
$chr_lines = strlen($chr_lines);
foreach($lines as $line)
{
$nline = str_pad($start_line, $chr_lines, ' ', STR_PAD_LEFT);
$output .= '<span style="color: grey;"
class="php_highlight_line">'.$nline. ':</span> '.$line;
$start_line ++;
}
$output .= '</span></code></pre>';
if($return === true) return $return;
else echo $output;
}
}
use this to disable selection of lines:
.php_highlight_line {
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
http://php.net/manual/en/function.highlight-file.php