-
-
Save weidizhang/5428237 to your computer and use it in GitHub Desktop.
PHP Rainbow BB Code Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Rainbow | |
{ | |
private $colors; | |
public function __construct() { | |
$this->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' | |
); | |
} | |
public function bbCode($text, $color) { | |
if ($text != " ") { | |
return "[color=\"#" . $color . "\"]" . $text . "[/color]"; | |
} | |
else { | |
return " "; | |
} | |
} | |
public function pickColor($text) { | |
return count($this->colors) / strlen($text); | |
} | |
public function generateBB($text) { | |
$code = ""; | |
$texts = str_split($text, count($this->colors)); | |
foreach ($texts as $t) { | |
for ($i = 0; $i < strlen($t); $i++) { | |
$code .= $this->bbCode($t[$i], $this->colors[(int) $this->pickColor($t) * $i]); | |
} | |
} | |
return $code; | |
} | |
} | |
$rainbow = new Rainbow(); | |
if (isset($_GET["str"])) { | |
echo $rainbow->generateBB($_GET["str"]); | |
} | |
else { | |
echo "Usage: ?str=[text2TurnIntoRainbowBbCode]"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment