Page 1 of 1

The last font tag (RegEx, maybe?)

Posted: Fri May 16, 2003 3:59 am
by Gleeb
I'm wondering how on earth I would find the *last* <font> tag that doesn't have a </font> after it is... I can't seem to find a way to do it in Regex... :| lil' help?

Posted: Fri May 16, 2003 5:13 am
by Gleeb
array_pop :)
Here's the code I came up with in the end. It highlights a file, plus line numbers, and retains colour across lines. Hurrah!

Code: Select all

<?PHP
$file = "source.php"; // Default page is always 1

if (isset($_GET['file']))
   $file = $_GET['file']; // If the page number was requested via GET, use that


$php_self_array = explode("/",$_SERVER['PHP_SELF']);
  // Directory Hack: http://127.0.0.1/filename.ext/arg becomes a valid and useful URL, with 'arg' being used for the page number

if (isset($php_self_array[2]) && $php_self_array[2]!="")
   $file = $php_self_array[2]; // use the page number gathered from above
?>
<style>
<!--

.hahaha {font-family: Courier, 'Courier New', sans-serif; font-size: 11px;}
.lnum {font-family: Courier, 'Courier New', sans-serif; font-size: 11px; font-weight: 700; text-align:right;}

//--!>
</style>
<table>
<?php
$contents = highlight_file($file, true);
$contents = explode("<br />", $contents);
$ln = 1;

$g=array(array('',''),array('',''));

foreach($contents as $line) {
//   array_reverse($g);
//   print_r($g);
   $line = '<font color="'.array_pop($g[1]).'">'.$line;
   print '<tr><td class="lnum">'.$ln++.']</td><td class="hahaha">'.$line.'</td>';
   preg_match_all('<font color="(#[0123456789AaBbCcDdEeFf]*)">',$line,$g);
}
?>
</table>