Re: Code Hightlights at Smarty Site

From: Date: Thu, 10 Apr 2003 01:36:41 +0000
Subject: Re: Code Hightlights at Smarty Site
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-9203@lists.php.net to get a copy of this message
Or you could try the faster: $url = "index.php"; /* for example */ $source = explode("<br />", preg_replace("\</?code\>Ui", "", highlight_file($url, true))); for ($i = 0, $_count = count($source); $i < $_count; $i++) $source[$i] = "<span style=\"color:black;\">" . str_pad($i, 5, "0",STR_PAD_LEFT) . "</span> " . $source[$i]; echo "<code>" . implode("<br />", $source) . "</code>"; "Alex = )" <alex@inses.biz> wrote in message news:3E94A86A.1030002@inses.biz... > Not so long ago I was wondering if anyone knew how all the code > published in the smarty wiki was processed to show up with line numbers > and nicely formatted. Well, as noone replied, I swept my tears away and > wrote the modifier myself, was worth onle 30 minutes of work and > produces amazing results. Feel free to use the code below. > > > /** > * parseCode() - Smarty Modifier - will create a nice table of > * all the <code> data in the passed string. > * > * @param $string (string) > * @return > */ > function parseCode($string){ > return > preg_replace_callback("/<code>(.*?)<\/code>/si",_makeCode,$string); > } > > > /** > * _makeCode() - callback from parseCode(); > * > * @param $matches > * @return > */ > function _makeCode($matches){ > $lines = explode("\n",trim($matches[1])); > if(count($lines) < 2){ > $lines = explode("<br>",trim($matches[1])); > } > $toReturn = "<table cellspacing=1 align=center>"; > $counter = 1; > foreach($lines as $line){ > $line = ereg_replace("[\t]","&nbsp;&nbsp;",$line); > $toReturn .= "<tr bgcolor=#eeeeee><td align=right><code><font > color=#009900>$counter.</font></code></td><td><code>&nbsp;$line&nbsp;</code> </td></tr>"; > $counter++; > } > $toReturn .= "</table><br>"; > return $toReturn; > } > > > > -- > .::....::.:...::...:..:.:::..:..::..::.::..:.:. > >

« previous php.smarty.general (#9203) next »