Generate Rainbow Text

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generate Rainbow Text

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

    PHP Code:
    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>'


  • #2
    Originally posted by arnage View Post
    Generates rainbow text in two specters, Rainbow Colors and Pinks & Blues.
    Where did you got this one ? :D 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 ... :p nice one btw ..

    Comment


    • #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().

      PHP Code:
      $string preg_replace_callback('/\[rainbow\](.*?)\[\/rainbow\]/i'
              
      create_function('$matched''return rainbow($matched[1]);'), 
              
      $string); 
      Last edited by arnage; 03.04.12, 19:32.

      Comment


      • #4
        Originally posted by arnage View Post
        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().

        PHP Code:
        $string preg_replace_callback('/\[rainbow\](.*?)\[\/rainbow\]/i'
                
        create_function('$matched''return rainbow($matched[1]);'), 
                
        $string); 
        i've got no freakin' idea :D

        Comment


        • #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.

          Comment


          • #6
            Originally posted by arnage View Post
            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 !

            Comment


            • #7
              Originally posted by arnage View Post
              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().

              PHP Code:
              $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.

              Comment


              • #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.
                Last edited by arnage; 04.04.12, 08:39.

                Comment


                • #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

                  PHP Code:
                      $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;
                      } 

                  Comment


                  • #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]

                    PHP Code:
                    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
                    PHP Code:
                        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
                    PHP Code:
                        $text preg_replace("/\[rainbow\](.*?)\[\/rainbow\]/e","rainbow('$1')",$text); 
                    Last edited by ori; 13.02.14, 09:10.

                    Comment


                    • #11
                      here

                      this was the function i used in my epix script
                      Code:
                      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;
                      }

                      Comment


                      • #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.

                        PHP Code:
                         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($letter21) . '</span>';
                                            } else {
                                                
                        $rainbowmsg .= ' ';
                                            }
                                            
                        $i++;
                                            if (
                        $i == $max) {
                                                
                        $i 0;
                                            }
                                        }
                                        return 
                        $rainbowmsg;
                                    }
                                }
                                return 
                        preg_replace_callback('#\[rainbow\](.*?)\[/rainbow\]#si''rainbow'$var);

                        Last edited by arnage; 14.02.14, 11:47.

                        Comment


                        • #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 Code:
                          <?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'), 06).';">'.$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.)
                          Last edited by Ghost; 19.02.14, 00:17.

                          Comment


                          • #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.

                            Comment


                            • #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. ;)

                              Comment

                              Working...
                              X