Generate Rainbow Text

Started on the old forum in April 2012 · view the original in the archive · old links redirect here

17 replies · 3,783 views · started 14 years ago · 2 min read

6 participants
arnage Lead · 811 posts #1

Generates rainbow text in two specters, Rainbow Colors and Pinks & Blues.

if ($_POST['submit'] == "Generate Rainbow Text") { 
  //color arrays 
  $rainbow = array('#ff0000', '#ff3300', '#ff6600', '#ff9900', '#ffcc00', 
  '#ffff00', '#ccff00', '#99ff00', '#66ff00', '#33ff00', '#00ff00', '#00ff33', 
  '#00ff66', '#00ff99', '#00ffcc', '#00ffff', '#00ccff', '#0099ff', '#0066ff', 
  '#0033ff', '#0000ff', '#3300ff', '#6600ff', '#9900ff', '#cc00ff', '#ff00ff', 
  '#ff00cc', '#ff0099', '#ff0066', '#ff0033'); 
  $pinkblue = array('#cc0000', '#ff6600', '#ff9900', '#99cc00', '#66cc00', 
  '#339900', '#339966', '#009999', '#0099cc', '#3399ff', '#3366ff', 
  '#3333ff', '#3300cc', '#6600cc', '#9900cc', '#cc00cc', '#ff00ff', '#ff00cc', 
  '#ff0099', '#ff0066', '#ff0033'); 
  //get the message 
  $message = strip_tags($_POST['message']); 
  if (empty($message)) { 
    echo("Oops! You didn't type any text to rainbow-ify!"); 
  } 
  else { 
    //decide which color array to use 
    if ($_POST['colorscheme'] == "rainbow") { $colorarr = $rainbow; } 
    else { $colorarr = $pinkblue; } 
    //split message into array of single letters 
    $messagearr = str_split($message); 
    $i = 0; //$i will keep count of which color in $colorarr we're up to 
    $max = count($colorarr); //the total number of colors in $colorarr 
    //loop through $messagearr 
    foreach ($messagearr as $letter) { 
      //if character isn't a space, assign color and add to $rainbowmsg: 
      if ($letter != " ") { 
        $rainbowmsg .= "<font color=\"".$colorarr[$i]."\">$letter</font>"; 
      } 
      //else add a space to $rainbowmsg: 
      else { $rainbowmsg .= " "; } 
      //+1 to $i (so that the next loop uses the next color in $colorarr): 
      $i++; 
      //if we've reached the end of $colorarr, set $i to zero to start again: 
      if ($i == $max) { $i = 0; } 
    } //(end foreach loop) 
    //output the rainbow code: 
    echo("Your Rainbow Code: 
    <form action=\"\" method=\"post\"> 
    <textarea rows=\"6\" cols=\"50\" name=\"rainbowcode\">$rainbowmsg 
    </textarea><br><br> 
    <input type=\"button\" value=\"Select All\" 
    onclick=\"this.form.rainbowcode.focus(); 
    this.form.rainbowcode.select();\"> 
    </form><br><br>"); 
  } //end else (message not empty) 
} //end if ($_POST) 
echo '
<form action="" method="post"> 
<input type="radio" name="colorscheme" value="rainbow" checked="checked"> Rainbow Colors <br> 
<input type="radio" name="colorscheme" value="pinkblue"> Pinks & Blues <br><br> 
Enter some text to color: <br> 
<textarea rows="6" cols="50" name="message"></textarea> <br><br> 
<input type="submit" name="submit" value="Generate Rainbow Text"> 
</form>';
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
just_m3. Developer · 199 posts #2

arnage wrote: Generates rainbow text in two specters, Rainbow Colors and Pinks & Blues.

Where did you got this one ? 😀 it looks verry similar to one that i've been decoded from a script to a user from my ex wap forum .. it was supposed to be "a hack code" (as he said) lol ... 😛 nice one btw ..

This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!

arnage Lead · 811 posts #3

Somewhere from the net, i have no idea where, someone here needed rainbow text so i googled this and saved into my php scrap file, today was listing it and find it again. 🤣

Btw, any idea on this? Its in rainbow().

$string = preg_replace_callback('/\[rainbow\](.*?)\[\/rainbow\]/i', 
		create_function('$matched', 'return rainbow($matched[1]);'), 
		$string);
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
just_m3. Developer · 199 posts #4

arnage wrote: Somewhere from the net, i have no idea where, someone here needed rainbow text so i googled this and saved into my php scrap file, today was listing it and find it again. 🤣

Btw, any idea on this? Its in rainbow().

$string = preg_replace_callback('/\[rainbow\](.*?)\[\/rainbow\]/i', 
		create_function('$matched', 'return rainbow($matched[1]);'), 
		$string);

i've got no freakin' idea 😀

This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!

arnage Lead · 811 posts #5

You are crazy i just might choke laughing. 🤣

I'll ride it all day and it became very frustrating, i've found at least 100 ways that don't work. : )))

If anyone have any idea please post. 🙂

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
just_m3. Developer · 199 posts #6

arnage wrote: You are crazy i just might choke laughing. 🤣

I'll ride it all day and it became very frustrating, i've found at least 100 ways that don't work. : )))

If anyone have any idea please post. :)

: )))))))))))) at least be happy that you found something ! 🤣

This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!

mFreak Developer · 66 posts #7

arnage wrote: Somewhere from the net, i have no idea where, someone here needed rainbow text so i googled this and saved into my php scrap file, today was listing it and find it again. 🤣

Btw, any idea on this? Its in rainbow().

$string = preg_replace_callback('/\[rainbow\](.*?)\[\/rainbow\]/i', 
		create_function('$matched', 'return rainbow($matched[1]);'), 
		$string);

that [rainbow] BBTag parser. It searches for text inside rainbow tags and passes them to rainbow function which returns string colored in rainbow colors and saves it in $string. By the looks of that it should work, whats the error. I think I have one of those scripts somewhere.

$("#mfreak").find(".head brain").clone();

Progress:

[|||___________________________] : 5%

Output:

Memory limit reached, unable to complete operation.

Support answer:

Try using a super uber strong mega computer to reach at least 10%.

👋

arnage Lead · 811 posts #8

Yes it does, it should, and after bouncing a few ideas this is closest i could come up with, wrote it by the book and i changed double to single quotes inside the rainbow() because of expanding vars inside create_function() and getting something undefined. I have one more idea to try but can't now, will latter.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
ori Lead · 512 posts #9

i also tried adding something like this to be used in a bbcode function heres how far i got this code is alot more simple

	$text = "this is a test message";
	$colors = array(
	'93FF00',
	'C8FF00',
	'FFFA00',
	'FFC300',
	'FE9400',
	'FF6700',
	'FF3800',
	'FF0000',
	'FF0039',
	'FE006E',
	'FF00A4',
	'FF00DF',
	'D900FF',
	'9E00FF',
	'6900FF',
	'3400FF',
	'0006FE',
	'003DFF',
	'006CFE',
	'0099FF',
	'00C8FF',
	'00FFFD',
	'00FFC3',
	'00FF8E'
	);
	for ($i = 0; $i < strlen($text); ++$i)
	{
	$texti = str_split($text);
	$textb = "<span style=\"color:$colors[$i]\">$texti[$i]</span>";
	echo $textb;
	}
ori Lead · 512 posts #10

heres a modified version your code i got it working in bbcode but it wont seperate inside the text field instead makes the whole text string rainbow using [rainbow]

function rainbow($message)
{
	$rainbow_array = array(
	'#ff0000',
	'#ff3300',
	'#ff6600',
	'#ff9900',
	'#ffcc00',
	'#ffff00',
	'#ccff00',
	'#99ff00',
	'#66ff00',
	'#33ff00',
	'#00ff00',
	'#00ff33',
	'#00ff66',
	'#00ff99',
	'#00ffcc',
	'#00ffff',
	'#00ccff',
	'#0099ff',
	'#0066ff',
	'#0033ff',
	'#0000ff',
	'#3300ff',
	'#6600ff',
	'#9900ff',
	'#cc00ff',
	'#ff00ff',
	'#ff00cc',
	'#ff0099',
	'#ff0066',
	'#ff0033'
	);

	$message_array = str_split($message);
	$i = 0;
	$max = count($rainbow_array);
	foreach ($message_array as $letter)
	{
		if ($letter != " ") $rainbow .= "<font color=\"".$rainbow_array[$i]."\">$letter</font>";
		else $rainbow .= " ";
		$i++;
		if ($i == $max) $i = 0;
	}
	return $rainbow;
}

bbcode can use this or

	if (preg_match("/\[rainbow\](.*?)/i",$text))
	{
		$text = preg_replace("/\[rainbow\](.*?)/i","\\1",$text);
		$text = rainbow($text);
	}

this is better if it works for your server

	$text = preg_replace("/\[rainbow\](.*?)\[\/rainbow\]/e","rainbow('$1')",$text);
Loony Senior · 258 posts #11

here

this was the function i used in my epix script

function rainbow($text)
{
$ret = '';

$colors = array(
'ff00ff',
'ff00cc',
'ff0099',
'ff0066',
'ff0033',
'ff0000',
'ff3300',
'ff6600',
'ff9900',
'ffcc00',
'ffff00',
'ccff00',
'99ff00',
'66ff00',
'33ff00',
'00ff00',
'00ff33',
'00ff66',
'00ff99',
'00ffcc',
'00ffff',
'00ccff',
'0099ff',
'0066ff',
'0033ff',
'0000ff',
'3300ff',
'6600ff',
'9900ff',
'cc00ff');
$i = 0;
$textlength = strlen($text);
while($i<=$textlength)
{
foreach($colors as $value)
{
if ($text[$i] != “”)
{
$ret .= "<span style='color:#'.$value.';”>'.$text[$i].'</span>";
}
$i++;
}
}
return $ret;
}

Creator of Epix.Mobi

Keep an Eye on us Big things coming soon!!!! Need something for your site hit me up here http://coding-talk.com/forum/main-forums/marketplace/153110-free-features-for-your-wapsite

arnage Lead · 811 posts #12

Thanks guys, this is applayed while ago but i forgot to post it. My bad. 🙁 And in it Metulj has noticed bug when its applaed in JohnCMS when convering chars or bb codes within rainbow bb tag, so its fixed. Anyway, here is the working version of this.

 private static function rainbow($var)
 {
		if (!function_exists('rainbow')) {
			function rainbow($var) {
				$var = html_entity_decode($var[1], ENT_QUOTES | ENT_XHTML, 'UTF-8');
				if (mb_stripos($var, 'lgbt') !== false) { // i had to add this ;)
					return;
				}
				$rainbow = array(
					'#ff0000', '#ff3300', '#ff6600', '#ff9900', '#ffcc00', '#ffff00', '#ccff00',
					'#99ff00', '#66ff00', '#33ff00', '#00ff00', '#00ff33', '#00ff66', '#00ff99',
					'#00ffcc', '#00ffff', '#00ccff', '#0099ff', '#0066ff', '#0033ff', '#0000ff',
					'#3300ff', '#6600ff', '#9900ff', '#cc00ff', '#ff00ff', '#ff00cc', '#ff0099',
					'#ff0066', '#ff0033'
				);
				$messagearr = preg_split('/(?<!^)(?!$)/u', $var);
				$i = 0;
				$max = count($rainbow);
				foreach ($messagearr as $letter) {
					if ($letter != ' ') {
						$rainbowmsg .= '<span style="color:' . $rainbow[$i] . ';">' . functions::checkout($letter, 2, 1) . '</span>';
					} else {
						$rainbowmsg .= ' ';
					}
					$i++;
					if ($i == $max) {
						$i = 0;
					}
				}
				return $rainbowmsg;
			}
		}
		return preg_replace_callback('#\[rainbow\](.*?)\[/rainbow\]#si', 'rainbow', $var);
}
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
Ghost Senior · 366 posts #13

this can be done also without an array. heres how i did it.

i put this together and tested it a few mins ago it should be working fine.

<?php
function rainbow($text){
$rainbow = '';
for($i=0; $i<strlen($text); ++$i){
$letter = str_split($text);
if($letter[$i] != ' '){
$rainbow .= '<span style="color:#'.substr(str_shuffle('ABCDEF0123456789'), 0, 6).';">'.$letter[$i].'</span>';
} else { 
$rainbow .= ' '; 
}
}
return $rainbow;
}

echo rainbow('this is a rainbow test');
?>

let me know what you guys think. im interested to hear comments.

(reason for edit?. pure boredom lol.)

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>
arnage Lead · 811 posts #14

Nice idea for random colors, i can picture people using it , but array has to be used if someone don't want colors to change on every refresh. 😊

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
Ghost Senior · 366 posts #15

if you saved the data from the function to the database first. then displayed the results. the colors would always remain the same. there would be no way of it changing on every refresh. it would only change on every refresh if you used the function to display the info as standard. echo'ing the results in this snippet was just a quick way of showing the work. 😉

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>
arnage Lead · 811 posts #16

The function is unusable in that way, its so much logical to write an array... It can be used for some ad links for example, or one line of text, but for storing a post in db nope. 🙁

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
ori Lead · 512 posts #17

the 2nd post i wrote works perfectly in my site as a function and in bbcode function

Ghost Senior · 366 posts #18

the above code snippet was just an example of how you could use without an array. i didnt realise i would have to go as far as writing this next function to add a bbcode parser etc. thought you guys may see the potential in the snippet and add as necessary.

<?php
function rainbow($data) {
$data = preg_replace_callback('/\[rainbow\](.*?)\[\/rainbow\]/msi', create_function('$matches', '{
$rainbow = \'\'; 
for($i=0; $i<strlen($matches[1]); ++$i){ 
$letter = str_split($matches[1]); 
if($letter[$i] != \' \'){ 
$rainbow .= \'<span style="color:#\'.substr(str_shuffle(\'ABCDEF0123456789\'), 0, 6).\';">\'.$letter[$i].\'</span>\'; 
} else {  
$rainbow .= \' \';  
} 
} 
return $rainbow;
}') , $data);
return $data;
}

echo rainbow('this is a test with [rainbow]rainbow colors[/rainbow] and more text'); 
?>

and although it may not be logical to save long strings of html to a database. thats not to say it can't be done.

truely i dont see any issues with the color randomly changing on a new page refresh anyway. and from what i can see from other posts all the functions would randomly change the color anyhow.

<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close