#!/usr/bin/php Processing ' . $file . "... "; // Read the file. $log = file($dir . $file, FILE_IGNORE_NEW_LINES); // Open our output file. if (!$handle = fopen('./output/' . $file . '.htm', 'w')) die("ERROR: Could not open output file\n"); // Output the header. fwrite($handle, ' aMSN Log — ' . $file . '

aMSN Log — ' . $file . '

'); // We're not in a colour to begin with. $in_colour = false; // Loop through each line. foreach ($log as $line) { $aidx = 0; while ($aidx != -1) { // Does the line *not* begin with |"L (ie. no colour info)? if ($aidx == 0 && substr($line, 0, 3) != '|"L') $bidx = -1; // Otherwise, we have colours. else { // If there's a |"LC, there is colour information. The colour // information is the 6 characters after this. if (substr($line, $aidx + 3, 1) == 'C') { // Get the colour. $colour = '#' . substr($line, $aidx + 4, 6); $aidx += 10; } // Other colours (eg. LGRA, LNOR, etc.) else { $colour_code = substr($line, $aidx + 3, 3); switch ($colour_code) { case 'RED': $colour = 'red'; break; case 'GRA': $colour = 'gray'; break; case 'NOR': $colour = 'black'; break; case 'ITA': $colour = 'blue'; break; case 'GRE': $colour = 'darkgreen'; break; default: $colour = 'black'; break; } $aidx += 6; } // Are we already in a colour tag? if ($in_colour == true) // End it. fwrite($handle, ''); // Output the colour. fwrite($handle, ''); // We're in a colour tag now. $in_colour = true; // Where are we up to now? Find the next colour tag. $bidx = strpos($line, '|"L', $aidx); if (!$bidx) $bidx = -1; } if (strpos($line, '|"L') === false) $string = $line; elseif ($bidx != -1) $string = substr($line, $aidx, ($bidx - $aidx)); else $string = substr($line, $aidx); fwrite($handle, htmlspecialchars($string)); $aidx = $bidx; } fwrite($handle, '
'); } // Close any remaining colour tag. if ($in_colour == true) fwrite($handle, '
'); // Output the footer. fwrite($handle, ' '); echo "DONE!\n"; } ?>