Nick color lavalair script

Started on the old forum in November 2010 · view the original in the archive · old links redirect here

11 replies · 2,379 views · started 16 years ago · 1 min read

TL;DR · summary of 11 replies
  • warchief suggested users can customize their nick color.
  • i0nutzxp provided a code snippet for setting user colors in an array.
  • frostymarvelous pointed out that either usernames or the list of colors needs to be limited, suggesting a solution function instead.

Written automatically from the replies by a language model on our own server. It can be wrong; the posts below are the source.

7 participants
SolidSnake Newbie · 1 posts #1

Hello friends, first sorry for the bad english, but I am from Brazil and I do not speak English very well. What prompted me to come to this forum, is that I am creating a wap site lavalair style, but do not know how to differentiate the color of nicknames of the users, wanted to differentiate, admin, moderator, male, female by the color of the nick. Would you like an orientation, thanks to all.

i0nutzxp Developer · 150 posts #2
list($name,$perm,sex) = mysql_fetch_array(mysql_query("SELECT name,  perm, sex FROM ibwf_users WHERE id='".getuid_sid($sid)."'"));
if($sex == "F"){
if($perm == 4)
  $color = "pink";
else if($perm == 3)
  $color = "red";
else .....
}else{
if($perm == 4)
  $color = "blue";
else if($perm == 3)
  $color = "black";
else .....
}
$name = "<font color=\"$color\">$name</font>";

something like that ...u can extend ...

<?php unlink('World/Europe/Romania.country'); ?>
reymon07 Junior · 47 posts #3

funny it is for n0ob c0ders lol..

Live Community

warchief Newbie · 5 posts #4

Like u reymon07? I have diffrent one.. Users can costumize their nick color just like changing email, location, shout out, etc.. But nick color will appear as Default .a link color when it is not set/costumized, not like other site that nick color will appear as BLACK if not set. Because nick will appear as black right?

subzero Super moderator Fellow · 3,954 posts #5

code like this

SUBZERO

I can do this but i do say going to be long code and costly

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

warchief Newbie · 5 posts #6

subzero alweiz want money as payment for a little easy code.. Haha

convictor Developer · 114 posts #7

I don't see any problem with coders asking compensation for ANY coding, because stuff that they share for free, are usually made like someone else did the coding

Why cry for a soul set free?

i0nutzxp Developer · 150 posts #8
<?PHP

$n = 'Test';
$new = '';
$i = 0;
$colors = array('red','blue','pink','purple','orange'); // '','','' ....
$len = strlen($n);
while($i<=$len-1){
$new .= '<font color="'.$colors[$i].'">'.$n[$i].'</font>';
$i++;
}
echo $new;

?>

2 minutes ... and in array put a no. of colors eq with the max name range:P

later edit for randomize the colors use shuffle($colors); before while loop

<?php unlink('World/Europe/Romania.country'); ?>
frostymarvelous Senior · 266 posts #9

tag? Seriously? Btw you need to factor that database storage of specific user color choices and also edit your entire code to display colored usernames wherever usernames appear.

Perfection comes at a cost

I accept liberty!

i0nutzxp Developer · 150 posts #10

For the lava use this. add a new varchar line named colcode in ibwf_users 😛

$uid = getuid_sid($sid);
list($nick) = mysql_fetch_array(mysql_query("SELECT name FROM ibwf_users WHERE id='".$uid."'"));
$i = 0;
$len = strlen($nick);
echo "<form action=\"set_col.php?action=colproc&sid=$sid\" method=\"post\">";
echo "<small>Make ur nick multicolored</small><br/>";
while($i<=$len-1){
echo "Word #".($i+1)." <input name=\"w$i\" maxlength=\"100\" size=\"3\"/><br/>";
$i++;
}
echo "<input type=\"submit\" value=\"Submit\"/>";
echo "</form>";
list($nick) = mysql_fetch_array(mysql_query("SELECT name FROM ibwf_users WHERE id='".$uid."'"));
$i = 0;
$len = strlen($nick);
$msg = '';
while($i<=$len-1){
$msg .= ''.$_POST['w'.$i].'-';
$i++;
}
$msg .= '1';
$res = mysql_query("UPDATE ibwf_users SET colcode='".mysql_real_escape_string($msg)."' WHERE id='".$uid."'");
if($res) echo " that\'s so good..";

and for core ..

function getnick_uid($uid)
{
  $q = mysql_fetch_assoc(mysql_query("SELECT name, colcode FROM ibwf_users WHERE id='".$uid."'"));
  return colorize($q['name'],$q['colcode']);
}
function colorize($n,$code){
$new = '';
$i = 0;
$colors = explode('-',$code);
$len = strlen($n);
#shuffle($colors);
while($i<=$len-1){
$new .= '<font color="'.$colors[$i].'">'.$n[$i].'</font>';
$i++;
}
return $new;
}

PS: make urself the code valid for xhtml validation... PS2: restrict user max len to max 10 chars ...

<?php unlink('World/Europe/Romania.country'); ?>
i0nutzxp Developer · 150 posts #11

colcode varchar(60) NULL // and in action where u change the nick add mysql_query("UPDATE ibwf_users SET colcode='' WHERE id='".$who."'); 😛

<?php unlink('World/Europe/Romania.country'); ?>
frostymarvelous Senior · 266 posts #12

username_color function

The scripts above have one flaw. either username or colors list must be limited. this is not successful in all cases and might cause problems. This function should be a panacea to all the problems. if you notice any bugs or errors, please post it.

<?php
//list($usercolors)= fetch from the database table
//we assume user is allowed to add colors in to the database separated by commas
//this can be any method that allows us to put it into an array
//it can even be a serialized array put into the db

$usercolors= "red,blue,yellow,green,violet,lime";//assumed selection of course
$username="frostymarvelous";//obviously, this should be db retrieval or other convenient method

$colors= explode(",",$usercolors);//put colors into an array

username_colors($username, $colors);

//so this funtion takes the username and array of colours and return a coloured username

function username_colors($username, $colors)//username is a string. colors is an array
{
$unlen= strlen($username);
$colsize= count($colors);

if ($unlen < $colsize)//this is to make sure that the colors are not more than the username chars
{
$diff= $colsize- $unlen;//find the difference between the two

while($diff != 0)
{
unset($colors[$diff]);//remove excess values
$diff --;
}
$colsize= count($colors);
}

$interval= ceil($unlen / $colsize);//this will allow us to make sure all chars have colours

$start = 0;
$newusername= "";

foreach($colors as $k => $v)//go through all colours
{
$next= $start + $interval;
$section = substr($username, $start, $interval);//get sections of username to colour

$newusername .=  "<span style=\"color:$v;\">$section</span>";//replace with colours

$start  += $interval;
}

echo $newusername;//do something with result. echo, return or whatever you wish
}
?>

Perfection comes at a cost

I accept liberty!

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close