Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Functions that can generate a sequence of ROYGBIV text for HTML or Minecraft using it's formatting codes.
<?php
/**
*
* @param string $text
* @param int $amount
*
* @return array
*
*/
function generate_ROYGBIV_HTML(string $text, int $amount = -1): array{
$return = [];
$colors = ["#FF0000", "#FF7400", "#FFD400", "#00FF00", "#00FFEC", "#0000FF", "#D800FF"];
$amount = ($amount < 1) ? strlen($text) : $amount;
$split = str_split($text);
for($i = 0; $i < $amount; ++$i){
$out = "";
$loop = 0;
foreach($split as $part){
$out .= "<p style='color: " . $colors[$loop++] . "'>" . $part . "<p/>";
if($loop > (count($colors) - 1)){
$loop = 0;
}
}
$color = array_shift($colors);
$colors[] = $color;
$return[] = $out;
}
return $return;
}
/**
*
* @param string $text
* @param int $amount
*
* @return array
*
*/
function generate_ROYGBIV_MC(string $text, int $amount = -1): array{
$return = [];
$colors = ["&c", "&6", "&e", "&a", "&b", "&9", "&5"];
$amount = ($amount < 1) ? strlen($text) : $amount;
$split = str_split($text);
for($i = 0; $i < $amount; ++$i){
$out = "";
$loop = 0;
foreach($split as $part){
$out .= $colors[$loop++] . $part;
if($loop > (count($colors) - 1)){
$loop = 0;
}
}
$color = array_shift($colors);
$colors[] = $color;
$return[] = $out;
}
return $return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment