~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
110
111
112
113
114
115
116
117
118
119
120
<html>
	<head>
		<title>Armagetron Advanced - Convert arma color codes 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: 1.0										######
######	Description: Please leave this header. Thanks!		######
######	Contact: zodiacsohma1@gmail.com						######
##################################################################

##################################################################
######  The reason I did $firstTime so that when the color	######
######	code is at 0, the stupid while loop	doesn't think	######
######	that it's false (as many would know, flase = 0)		######
##################################################################

if (isset($_POST["convert"]))
{
	// your armagetron color coded string goes into the $source_string
	$source_string = $_POST["text"];
	$new_string = '';
	$chars = 0;

	if ($source_string != "")
	{
		$strPos = strpos($source_string, "0x");		// get the first point of the color code
		$strPos++;									// increment it so that if the first code is at the beginning, the script won't fail
		$new_strPos = 0;							// the length the substr would be taking from $source_string
		$firstTime = true;							// this is going to be the first time the color code is found

		while ($strPos != false)
		{
			if ($firstTime == true)					// if this is the first time finding a color code
			{
				$colorCode = substr($source_string, ($strPos-1), 8);		// get the color code from $source_string
				$colorCode = str_replace("0x", "#", $colorCode);			// replace 0x with #
				
				if (($new_strPos == 0) && (($strPos-1) > 0))				// if the color code was found beyond the 0 mark, then
				{
					$new_string .= substr($source_string, $new_strPos, (($strPos-1) - $new_strPos));	 // read in the first bit
					$chars += (($strPos-1) - $new_strPos);
				}
				
				$new_strPos = $strPos + 7;		// set the new length to get
				$strPos = strpos($source_string, "0x", $strPos);		// get the next color code's position
				if ($strPos == false)			// if there is none
				{
					$strPos = strlen($source_string);	// make the strpos the length of the entire source string
					
					// put the current color and the extra into $new_string
					$new_string .= '<font color="'.$colorCode.'">'.substr($source_string, $new_strPos, ($strPos - $new_strPos)).'</font>';	
					$chars += ($strPos - $new_strPos);
					$strPos = false;		//now turn this back to it's original value, false
				}
				else		// if there is another
				{
					// put the current color and the extra into $new_string
					$new_string .= '<font color="'.$colorCode.'">'.substr($source_string, $new_strPos, ($strPos - $new_strPos)).'</font>';
					$chars += ($strPos - $new_strPos);
				}
				$firstTime = false;
			}
			else	// if this is not the first time, most of the things that had taken place will also take place here. No confusion necessary.
			{
				$colorCode = substr($source_string, $strPos, 8);
				$colorCode = str_replace("0x", "#", $colorCode);
				
				if (($new_strPos == 0) && ($strPos > 0))
				{
					$new_string .= substr($source_string, $new_strPos, ($strPos - $new_strPos));
					$chars += ($strPos - $new_strPos);
				}
				
				$new_strPos = $strPos + 8;
				$strPos = strpos($source_string, "0x", $strPos+1);
				if ($strPos == false)
				{
					$strPos = strlen($source_string);
					$new_string .= '<font color="'.$colorCode.'">'.substr($source_string, $new_strPos, ($strPos - $new_strPos)).'</font>';
					$chars += ($strPos - $new_strPos);
					$strPos = false;
				}
				else
				{
					$new_string .= '<font color="'.$colorCode.'">'.substr($source_string, $new_strPos, ($strPos - $new_strPos)).'</font>';
					$chars += ($strPos - $new_strPos);
				}
			}
		}
		// now write the new string to the browser page
?>
		<center>
			<div class="text_header" align="center"><br><?php echo $new_string; ?></div>
			<textarea cols="100%" rows="35"><?php echo $new_string; echo "\n\nNo. Of letters (disregarding color codes): ".$chars; ?></textarea>
			<form action=""><input type="submit" value="Home"></form>
		</center>
<?php
	}
}
else
{
?>
		Enter your color coded arma string into the box and click "Convert"
		<form method="post">
			<table>
				<tr><td><input type="text" name="text" class="text_box" size="100" value="Your color coded text go here"></td></tr>
				<tr><td><input type="submit" name="convert" value="Convert"></td></tr>
			</table>
		</form>
<?php
}
?>
	</body>
</html>