~zodiacsohma/armagetronad/arma_colors_to_html_codes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<html>
	<head>
		<title>Armagetron Advanced - Colors to Html</title>
		<link rel="stylesheet" type="text/css" href="changing_colors.css">
	</head>
	<body>
<?php
##################################################################
######	Convert Armagetron color codes into	HTML format		######
##################################################################
######	Script by: LOVER$BOY								######
######	Version: 2.0										######
######	Description: Please leave this header. Thanks!		######
######	Contact: zodiacsohma1@gmail.com						######
##################################################################

$converted = false;
if (isset($_POST["convert"]))
{
    $text = $_POST["text"];
    //$text = htmlentities('0xff0000Alpha 0x00ffffProject 0x33ebff<0x78ff29<0xff3c1f<  0xff0000LOVER$BOYs 0xff301eH0xffbf1ee0xb1ff1el0x1eff21l0x14ffacs 0xff301eR0xffb41fa0xcfff1ec0x58ff29i0x28ff76n0x29fff0g  0x33ebff>0x78ff29>0xff3c1f>');
    
    //echo "Searching String: Alpha Project <<< LOVER\$BOYs Hells Racing!<br />\n";
    
    echo "            <pre style=\"background: #000000; padding: 10px; font-size:16px;\">\n";
    
    $pos = strpos($text, "0x");
    $prevpos = 0;
    
    $line = "";
    while ($pos !== false)
    {
        //  get color code from function
        $color = extractColorCode($text, $pos);
        
        //  store previous and continue
        $prevpos = $pos;
        $pos = strpos($text, "0x", $pos + 1);
        
        //  checking whether there is anymore to do
        if ($pos !== false)
            //  if so, then store only the string in between new color code and previous color code
            $str = substr($text, $prevpos, $pos - $prevpos);
        else
            //  if not, then store the rest of the string from previous color code
            $str = substr($text, $prevpos);
        
        //  finally, output the string for each parsing
        $line .= '<span style="color: #'.$color.';">'.$str.'</span>';
    }
    
    echo $line;
    $converted = true;
    echo "</pre>\n";
}
?>
		Enter your color coded arma string into the box and click "Convert"
		<form method="post">
		<table>
<?php
if ($converted)
{
?>
                    <tr><td><b>Display:</b><br /><textarea name="display" class="text_box" cols="90" rows="12"><?php echo $line; ?></textarea></td></tr>
                    <tr><td><b>Original:</b><br /><textarea name="text" class="text_box" cols="90" rows="12"><?php echo $_POST["text"]; ?></textarea></td></tr>
<?php
}
else
{
?>
                    <tr><td><textarea name="text" class="text_box" cols="90" rows="12">Your color coded text go here</textarea></td></tr>
<?php
}
?>
                    <tr><td><input type="submit" name="convert" value="Convert"></td></tr>
<?php

function extractColorCode($str, &$pos)
{
    //  list of valid chars
    $validChars = array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
    
    $colorcode = "";
    
    //  increment twice to avoid 0x
    $pos += 2;
    
    $done = false;
    for($i = 0; (($i < 6) && !$done); $i++)
    {
        $cs = substr($str, $pos, 1);
        foreach ($validChars as $char)
        {
            if ($cs == $char)
            {
                $colorcode .= $char;
                $pos++;
            }
        }
    }
    //substr($text, $pos, 8);
    
    return $colorcode;
}
?>
            </table>
        </form>
    </body>
</html>