note 78558 added to function.highlight-file

From: Date: Wed, 17 Oct 2007 12:24:31 +0000
Subject: note 78558 added to function.highlight-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-131451@lists.php.net to get a copy of this message
A function which parses the output of highlight file and replaces &lt;span&gt; wits &lt;a&gt;, replaces the style="color: #XXXXXX" part with class="cX", storing the colors in some css rules; that way you get a smaller output size (ratio is about about 1.2 ~ 1.4): <code> <?php function highlight_file2($fl,$ret){ if(!isset($ret)) $ret = false; $str = highlight_file($fl,true); preg_match_all("/\<span style=\"color: #([\d|A|B|C|D|E|F]{6})\"\>.*?\<\/span\>/",$str,$mtch); $m = array_unique($mtch[1]); $cls = '<style type="text/css">'."\n"; $rpl = array("</a>"); $mtc = array("</span>"); $i = 0; foreach($m as $clr) { $cls .= "a.c".$i."{color: #".$clr.";}\n"; $rpl[] = "<a class=\"c".$i++."\">"; $mtc[] = "<span style=\"color: #".$clr."\">"; } $cls .= "</style>"; $str2 = str_replace($mtc,$rpl,$str); if($ret) return $str2; else echo $str2; } ?> </code> ---- Server IP: 69.147.83.197 Probable Submitter: 80.97.9.145 ---- Manual Page -- http://www.php.net/manual/en/function.highlight-file.php Edit -- https://master.php.net/note/edit/78558 Del: integrated -- https://master.php.net/note/delete/78558/integrated Del: useless -- https://master.php.net/note/delete/78558/useless Del: bad code -- https://master.php.net/note/delete/78558/bad+code Del: spam -- https://master.php.net/note/delete/78558/spam Del: non-english -- https://master.php.net/note/delete/78558/non-english Del: in docs -- https://master.php.net/note/delete/78558/in+docs Del: other reasons-- https://master.php.net/note/delete/78558 Reject -- https://master.php.net/note/reject/78558 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131451) next »