Advertisement
VyaraG

RainbowLetters

Apr 24th, 2015
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. <?php
  2. //1st - take input; str to int; int to hex
  3. $text = $_GET['text'];
  4. $red=dechex(intval($_GET['red']));
  5. //var_dump($red)int - hex;
  6. $green=dechex(intval($_GET['green']));
  7. $blue=dechex(intval($_GET['blue']));
  8. $nth=$_GET['nth'];
  9. //2nd - valid RGB
  10. if(strlen((string)$blue)==1){
  11.     $blue.='0';
  12. }
  13. if(strlen(strval($red))==1){
  14.     $red.='0';
  15. }
  16. if(strlen(strval($green))==1){
  17.     $green.='0';
  18. }
  19. $validRGB=strtolower("#".$red.$green.$blue);
  20. //var_dump($validRGB);
  21. $result="<p>";
  22. for($i=0; $i<strlen($text); $i++){
  23.  
  24.     if(($i+1)%$nth==0){
  25.         $result.= "<span style=\"color: $validRGB\">".htmlspecialchars($text[$i])."</span>";
  26.     }else{
  27.         $result.= htmlspecialchars($text[$i]);
  28.     }
  29. }
  30. $result .= "</p>";
  31.     echo $result;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement