~zodiacsohma/armagetronad/arma_colors_to_html_codes

« back to all changes in this revision

Viewing changes to Converting RGB Colors to HTML Colors.php

  • Committer: zodiacsohma1 at gmail
  • Date: 2012-09-17 03:56:35 UTC
  • Revision ID: zodiacsohma1@gmail.com-20120917035635-3eag6vs7suevmaf7
Adding files to branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
        <head>
 
3
                <title>Armagetron Advanced - Convert arma color codes to HTML</title>
 
4
                <link rel="stylesheet" type="text/css" href="changing_colors.css">
 
5
        </head>
 
6
        <body>
 
7
<?php
 
8
##################################################################
 
9
######  Convert Armagetron color codes into     HTML format             ######
 
10
##################################################################
 
11
######  Script by: LOVER$BOY                                                            ######
 
12
######  Version: 1.0                                                                            ######
 
13
######  Description: Please leave this header. Thanks!          ######
 
14
######  Contact: zodiacsohma1@gmail.com                                         ######
 
15
##################################################################
 
16
 
 
17
##################################################################
 
18
######  The reason I did $firstTime so that when the color      ######
 
19
######  code is at 0, the stupid while loop     doesn't think   ######
 
20
######  that it's false (as many would know, flase = 0)         ######
 
21
##################################################################
 
22
 
 
23
if (isset($_POST["convert"]))
 
24
{
 
25
        // your armagetron color coded string goes into the $source_string
 
26
        $source_string = $_POST["text"];
 
27
        $new_string = '';
 
28
        $chars = 0;
 
29
 
 
30
        if ($source_string != "")
 
31
        {
 
32
                $strPos = strpos($source_string, "0x");         // get the first point of the color code
 
33
                $strPos++;                                                                      // increment it so that if the first code is at the beginning, the script won't fail
 
34
                $new_strPos = 0;                                                        // the length the substr would be taking from $source_string
 
35
                $firstTime = true;                                                      // this is going to be the first time the color code is found
 
36
 
 
37
                while ($strPos != false)
 
38
                {
 
39
                        if ($firstTime == true)                                 // if this is the first time finding a color code
 
40
                        {
 
41
                                $colorCode = substr($source_string, ($strPos-1), 8);            // get the color code from $source_string
 
42
                                $colorCode = str_replace("0x", "#", $colorCode);                        // replace 0x with #
 
43
                                
 
44
                                if (($new_strPos == 0) && (($strPos-1) > 0))                            // if the color code was found beyond the 0 mark, then
 
45
                                {
 
46
                                        $new_string .= substr($source_string, $new_strPos, (($strPos-1) - $new_strPos));         // read in the first bit
 
47
                                        $chars += (($strPos-1) - $new_strPos);
 
48
                                }
 
49
                                
 
50
                                $new_strPos = $strPos + 7;              // set the new length to get
 
51
                                $strPos = strpos($source_string, "0x", $strPos);                // get the next color code's position
 
52
                                if ($strPos == false)                   // if there is none
 
53
                                {
 
54
                                        $strPos = strlen($source_string);       // make the strpos the length of the entire source string
 
55
                                        
 
56
                                        // put the current color and the extra into $new_string
 
57
                                        $new_string .= '<font color="'.$colorCode.'">'.substr($source_string, $new_strPos, ($strPos - $new_strPos)).'</font>';  
 
58
                                        $chars += ($strPos - $new_strPos);
 
59
                                        $strPos = false;                //now turn this back to it's original value, false
 
60
                                }
 
61
                                else            // if there is another
 
62
                                {
 
63
                                        // put the current color and the extra into $new_string
 
64
                                        $new_string .= '<font color="'.$colorCode.'">'.substr($source_string, $new_strPos, ($strPos - $new_strPos)).'</font>';
 
65
                                        $chars += ($strPos - $new_strPos);
 
66
                                }
 
67
                                $firstTime = false;
 
68
                        }
 
69
                        else    // if this is not the first time, most of the things that had taken place will also take place here. No confusion necessary.
 
70
                        {
 
71
                                $colorCode = substr($source_string, $strPos, 8);
 
72
                                $colorCode = str_replace("0x", "#", $colorCode);
 
73
                                
 
74
                                if (($new_strPos == 0) && ($strPos > 0))
 
75
                                {
 
76
                                        $new_string .= substr($source_string, $new_strPos, ($strPos - $new_strPos));
 
77
                                        $chars += ($strPos - $new_strPos);
 
78
                                }
 
79
                                
 
80
                                $new_strPos = $strPos + 8;
 
81
                                $strPos = strpos($source_string, "0x", $strPos+1);
 
82
                                if ($strPos == false)
 
83
                                {
 
84
                                        $strPos = strlen($source_string);
 
85
                                        $new_string .= '<font color="'.$colorCode.'">'.substr($source_string, $new_strPos, ($strPos - $new_strPos)).'</font>';
 
86
                                        $chars += ($strPos - $new_strPos);
 
87
                                        $strPos = false;
 
88
                                }
 
89
                                else
 
90
                                {
 
91
                                        $new_string .= '<font color="'.$colorCode.'">'.substr($source_string, $new_strPos, ($strPos - $new_strPos)).'</font>';
 
92
                                        $chars += ($strPos - $new_strPos);
 
93
                                }
 
94
                        }
 
95
                }
 
96
                // now write the new string to the browser page
 
97
?>
 
98
                <center>
 
99
                        <div class="text_header" align="center"><br><?php echo $new_string; ?></div>
 
100
                        <textarea cols="100%" rows="35"><?php echo $new_string; echo "\n\nNo. Of letters (disregarding color codes): ".$chars; ?></textarea>
 
101
                        <form action=""><input type="submit" value="Home"></form>
 
102
                </center>
 
103
<?php
 
104
        }
 
105
}
 
106
else
 
107
{
 
108
?>
 
109
                Enter your color coded arma string into the box and click "Convert"
 
110
                <form method="post">
 
111
                        <table>
 
112
                                <tr><td><input type="text" name="text" class="text_box" size="100" value="Your color coded text go here"></td></tr>
 
113
                                <tr><td><input type="submit" name="convert" value="Convert"></td></tr>
 
114
                        </table>
 
115
                </form>
 
116
<?php
 
117
}
 
118
?>
 
119
        </body>
 
120
</html>
 
 
b'\\ No newline at end of file'