Converting LFS Colours
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
.lfs_col0 {color : #000000;}
.lfs_col1 {color : #ff0000;}
.lfs_col2 {color : #00ff00;}
.lfs_col3 {color : #ffff00;}
.lfs_col4 {color : #0000ff;}
.lfs_col5 {color : #ff00ff;}
.lfs_col6 {color : #00ffff;}
.lfs_col7 {color : #ffffff;}
.lfs_col8, .lfs_col9 {color : #8a8a8a;}function LFSColours(str) {
var parts = str.split(/(\^\d)/g).slice(1);
var res = "";
parts.forEach(function(el, i, arr) {
(i % 2 === 0) ? arr[i] = el.slice(1) : res += '<span class="lfs_col' + arr[i-1] + '">' + el + '</span>';
});
return res;
}var str = '^1[TC]\u00bbPete\u00ab';
document.body.innerHTML = LFSColours(str);function LFSColours($raw) {
if ($raw === null) return "";
$parts = preg_split('/(?=\^\d)/', $raw);
$res = "";
foreach ($parts as $part) {
if (preg_match('/(\^\d)(.*)/', $part, $m) === 1) {
$res .= "<span class='lfs_col" . $m[1][1] . "'>" . htmlspecialchars($m[2]) . "</span>";
}
else $res .= "<span class='lfs_col8'>" . htmlspecialchars($part) . "</span>";
}
return $res;
}$str = '^1[TC]\u00bbPete\u00ab';
echo(LFSColours($str));