PDA

View Full Version : Rainbow Username


Black Snow
03-14-2013, 09:15 PM
Hi,

Can anyone tell me why this won't work? It's for creating rainbow usernames but for some reason it doesn't work.

if( strpos( $user['musername'], 'rainbow: true;' ) !== false )
{
$i = $b = 0;

$username = '';

$colours = array('d31539', 'ff7e00', 'ffc20e', '90d125', '187acb', '6f3198', 'ab1d8e');

while( $i < strlen( $user['username'] ) )
{
if( $b > ( count( $colours ) - 1 ) ) $b = 0;

$username .= '<span style="color: #' . $colours[ $b ] . '">' . $user['username'][$i] . '</span>';

++$b;
++$i;
}

$user['musername'] = '<strong>' . $username . '</strong>';

I also made the usergroup HTML markup to:
<strong style="color: #FFBC58; rainbow: true;">
</strong>

nerbert
03-15-2013, 01:51 AM
You have to split the string up into an array. Here's what I got working:


function rainbow($str)
{
$array = str_split($str);
$i = $b = 0;
$str = '';
$colours = array('d31539', 'ff7e00', 'ffc20e', '90d125', '187acb', '6f3198', 'ab1d8e');
while( $i < count($array) )
{
if( $b > ( count( $colours ) - 1 ) ) $b = 0;

$str .= '<span style="color: #' . $colours[ $b ] . '">' . $array[$i] . '</span>';

++$b;
++$i;
}
return $str;
}

Black Snow
03-15-2013, 09:28 PM
What hook location did you use? Could you post a screenshot of it?

For some reason, it turns quite a lot of my text a yellow colour but no rainbow effect.

kh99
03-16-2013, 12:06 AM
I found that the code you posted in post #1 works using hook fetch_musername, but you're just missing a closing '}' at the end.

Black Snow
03-17-2013, 08:41 PM
I found that the code you posted in post #1 works using hook fetch_musername, but you're just missing a closing '}' at the end.

Could you post a screenshot if it working? I used the code that nerbert posted with the same hook location you mentioned and it didn't work.

Edit: Got it working. You can close this thread.