PHP ver gevorderde |
|
ik heb ergens een higlighter gevonden wat mijn script kleurt en lijn nummers weergeeft.
maar ik wil nudat de totale breedte van het code blok niet groter is dan 913px; (de breedte van mijn div waarin alle content kom)
maar ik rkigj dat niet voor mekaar
stijl:
table.code .linenumbers, table.code .code, table.code { background-color: #F2F2F2; font-size: 9pt; font-family: "Courier New"; }
table.code { display: block; width: 400px; border: 10px solid #F2F2F2; border-bottom: 0px solid black; }
table.code .linenumbers { display: block; }
table.code .code {display: block; overflow: auto;}
table.code .linenumbers, table.code .code, table.code { background-color: #F2F2F2; font-size: 9pt; font-family: "Courier New"; } table.code { display: block; width: 400px; border: 10px solid #F2F2F2; border-bottom: 0px solid black; } table.code .linenumbers { display: block; } table.code .code {display: block; overflow: auto;}
de highlight functie:
function highlight($code){
stripslashes($code);
$highlighted = highlight_string($code, true);
$lines = explode('<br />', $highlighted);
echo '<table class="code">' . "\n";
echo '<tr>' . "\n";
echo '<td id="linenumbers">' . "\n";
foreach ($lines as $lineID => $line)
{
$spaces = strlen(count($lines)) - strlen($lineID + 1);
for ($i = 0; $i < $spaces; $i ++)
{
echo ' ';
}
echo $lineID + 1 . '<br />' . "\n";
}
echo '</td>' . "\n";
echo '<td class="code"><br />' . "\n";
foreach ($lines as $line)
{
echo $line . '<br />' . "\n";
}
echo '</td>' . "\n";
echo '</tr>' . "\n";
echo '</table>' . "\n";
}
function highlight($code){ $lines = explode('<br />', $highlighted); echo '<table class="code">' . "\n"; echo '<td id="linenumbers">' . "\n"; foreach ($lines as $lineID => $line) { for ($i = 0; $i < $spaces; $i ++) { } echo $lineID + 1 . '<br />' . "\n"; } echo '<td class="code"><br />' . "\n"; foreach ($lines as $line) { echo $line . '<br />' . "\n"; } }
alvast bedankt
|