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.
Nick color lavalair script
Started on the old forum in November 2010 · view the original in the archive · old links redirect here
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.
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 ...
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?
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... _______…
<?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
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!
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 ...
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!