I recommend that you put the string first through the functions in this forum post and then through these for the best result.
Live For Speed Functions
ECMA-48 Escape String (Linux Console)
HTML Markup
Strip all LFS codes
Live For Speed Functions
ECMA-48 Escape String (Linux Console)
<?php
# Convert Live For Speed String into an ECMA-48 escaped string.
function lfs_str_convert_console($str)
{
// Replace Set
$replaceArray = array("\033[30m", "\033[31m", "\033[32m", "\033[33m", "\033[34m", "\033[35m", "\033[36m", "\033[37m", "\033[39m", "\033[0m");
// Extra State Information
$isTagOpen = FALSE;
// Parse String
for ($i = 0, $j = 1, $l = strlen($str); $i < $l; ++$i, ++$j)
{
/* Handle Color Codes */
if ($str{$i} == '^' && is_numeric($str{$j}))
{
// Get array values' length.
$deltaLen = strlen($replaceArray[$str[$j]]);
// Set tag status
if ($str{$j} < 8)
$isTagOpen = TRUE;
else
$isTagOpen = FALSE;
// Place ECMA-48 Charaters into String.
$str = substr($str, 0, $i) . $replaceArray[$str[$j]] . substr($str, $i);
// Move Pointer Past The Change.
$i += $deltaLen; $j += $deltaLen;
// Get new String Length.
$l = strlen($str);
// Remove The Formatting.
$str[$i] = NULL; # Remove ^
$str[$j] = NULL; # Remove Int.
}
}
// Close any tag left open.
if ($isTagOpen)
$str .= "\033[0m";
return $str;
}
?>
<?php
# Convert Live For Speed String into an HTML Mark'ed Up String.
function lfs_str_convert_html($str)
{
// Replace Set
$replaceArray = array('000', 'F00', '0F0', 'FF0', '00F', 'F0F', '0FF', 'FFF');
// Extra State Information
$isTagOpen = FALSE;
// Parse String
for ($i = 0, $j = 1, $l = strlen($str); $i < $l; ++$i, ++$j)
{
/* Handle Color Codes */
if ($str{$i} == '^' && is_numeric($str{$j}))
{
if ($isTagOpen == TRUE)
{
// Set State.
$isTagOpen = FALSE;
// Inject Close Tag
$str = substr($str, 0, $i) . '</span>' . substr($str, $i);
// Move Str pointers Past Δ.
$i += 7; $j += 7; $l = strlen($str);
}
if ($str{$j} < 8)
{
// Set State
$isTagOpen = TRUE;
// Inject HTML Markup
$str = substr($str, 0, $i) . '<span style="color: #'.$replaceArray[$str[$j]].';">' . substr($str, $i);
// Move Pointer Past The Change.
$i += 27; $j += 27;
// Get new String Length.
$l = strlen($str);
}
// Remove The Formatting.
$str[$i] = NULL; # Remove ^.
$str[$j] = NULL; # Remove Int.
}
}
// Close any tag left open.
if ($isTagOpen)
$str .= '</span>';
return $str;
}
?>
<?php
# Strip All Live For Speed Markup From The String.
function lfs_str_strip($str)
{
return str_replace(array('^0','^1','^2','^3','^4','^5','^6','^7','^8','^9'), array(), str_replace(array('^d','^s','^c','^a','^q','^t','^l','^r','^v'), array('\\','/',':','*','?','"','<','>','|'), $str));
}
?>