Advertisement
dimipan80

Rainbow Letters

May 1st, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. <?php
  2. $text = $_GET['text'];
  3. $letterNumber = (int)$_GET['nth'];
  4. $colorNum = array((int)$_GET['red'], (int)$_GET['green'], (int)$_GET['blue']);
  5. $color = '#';
  6. foreach ($colorNum as $num) {
  7.     $hex = dechex($num);
  8.     if (strlen($hex) === 1) {
  9.         $hex = '0' . $hex;
  10.     }
  11.     $color .= $hex;
  12. }
  13.  
  14. $style = "style=\"color: {$color}\"";
  15. $result = '<p>';
  16. for ($i = 0; $i < strlen($text); $i++) {
  17.     if ((($i + 1) % $letterNumber) == 0) {
  18.         $result .= "<span {$style}>" . htmlspecialchars($text[$i]) . '</span>';
  19.     } else {
  20.         $result .= htmlspecialchars($text[$i]);
  21.     }
  22. }
  23.  
  24. echo $result . '</p>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement