[PHP] ^# Color Function

Status
Not open for further replies.
Joined
May 6, 2008
Messages
233
Reaction score
55
PHP:
function textcolor($input_text){
	$output_text = 
		str_ireplace(
			array(
				"^0", //Grey
				"^1", //Red
				"^2", //Green
				"^3", //Blue
				"^4", //Yellow
				"^5", //Dark Red
				"^6", //Dark Green
				"^7", //Dark Blue
				"^8", //Dark Yellow
				"^9", //White
			),
			array(
				"<font color='#808080'>", //Grey
				"<font color='#FF0000'>", //Red
				"<font color='#00FF00'>", //Green
				"<font color='#0000FF'>", //Blue
				"<font color='#FFFF00'>", //Yellow
				"<font color='#800000'>", //Dark Red
				"<font color='#008000'>", //Dark Green
				"<font color='#000080'>", //Dark Blue
				"<font color='#808000'>", //Dark Yellow
				"<font color='#FFFFFF'>", //White
			),
			"$input_text</font>"
		);
	return print($output_text);
}
.
Technically the font only needs to be closed at the end.



I only did this because i got tired of seeing ^1blah^2blah in rankings and crap.

Feel free to criticize or give tips.
 
Last edited:
sorry for anoyying, can u add all to here?

PHP:
<?
SetTitle("Final Revolution Anniversary // Player Ranking");
?><head>
<script language="JavaScript" type="text/JavaScript">
<!--



function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>
<table width="200" border="0" align="center">
  <tr>
    <td> </td>
  </tr>
  <tr>
    <td><div align="center"><img src="img/bn_legend.png" width="450" height="25"></div></td>
  </tr>
  <tr>
    <td><table width="460" border="0" align="center">
      <tr>
        <td style="background-repeat: repeat; background-position: center top" width="590" valign="top"><p>
            <div align="center">
              <form method="GET" name="indsearch" action="index.php">
                <input type="hidden" name="gunz" value="ranking" />
                <p align="center">
                  <select name="type">
                    <option value="1">Character Name</option>
                  </select>
                  <input type="text" name="name" />
                  <input name="submit" type="submit" value="Search" />
                </p>
              </form>
          </div></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><div align="center">
      <table border="0" width="450">
        <tr align="center">
          <td width="1" height="21"></td>
          <td width="72" height="21" valign="bottom" align="center" class="Estilo7"> <b>Ranking</b></td>
          <td width="155" height="21" valign="bottom" align="center" class="Estilo7"> <b>Character Name</b></td>
          <td width="61" height="21" valign="bottom" align="center" class="Estilo7"> <b>Level</b></td>
          <td width="125" height="21" valign="bottom" align="center" class="Estilo7"> <b>Kill/Death Ratio</b></td>
          <td width="1" height="21"> </td>
        </tr>
        <tr>
          <td width="1"> </td>
          <td colspan="4" valign="top">
            <div align="center">
              <table border="0" style="border-collapse: collapse" width="450">
                <tr>
                  <td width="67" height="10"></td>
                  <td width="159"></td>
                  <td width="59"></td>
                  <td width="122"></td>
                </tr>
                <?
                                                          if( isset($_GET['type']) && isset($_GET['name']) )
                                                        {
                                                            $search = 1;
                                                            $type = clean($_GET['type']);
                                                            if($type == 1)
                                                            {
                                                                $squery = "SELECT CID, Level, XP, KillCount, Ranking, PlayTime, DeathCount FROM Character WHERE Name = '$name'";
                                                            }
                                                            elseif($type == 2)
                                                            {
                                                                if( mssql_num_rows($accountq) == 1 )
                                                                {
                                                                $accountdata = mssql_fetch_row($accountq);
                                                                $aid = $accountdata[0];
                                                                $squery = "SELECT CID, Level, XP, PlayTime, KillCount, DeathCount FROM Character WHERE AID = '$aid' AND (DeleteFlag=NULL OR DeleteFlag=0) ORDER BY Level DESC, XP DESC, KillCount DESC, DeathCount ASC";
                                                                }
                                                                else
                                                                {
                                                                    echo'
                                                               <tr>
                                            <td colspan="5">
                                              <p align="center" class="Estilo1">No Data //</td>
                                          </tr>';
                                                                }
                                                            }
                                                            else
                                                            {
                                                                $search = 0;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            $search = 0;
                                                        }

                                                        if($search == 0 )
                                                        {switch( clean($_GET['p']) )
                                                        {
                                                            case "":
                                                                $rank = "Ranking >= 1 AND Ranking <= 25";
                                                            break;
                                                            case "2":
                                                                $rank = "Ranking > 25 AND Ranking <= 50";
                                                            break;
                                                            case "3":
                                                                $rank = "Ranking > 50 AND Ranking <= 75";
                                                            break;
                                                            case "4":
                                                                $rank = "Ranking > 76 AND Ranking <= 100";
                                                            break;
                                                            default:
                                                                $rank = "Ranking <= 25";
                                                            break;
                                                        }
                                                        $res = mssql_query("SELECT TOP 25 CID, Level, PlayTime, XP, Ranking, KillCount, DeathCount FROM Character WHERE $rank ORDER BY Ranking ASC");
														  }
                                                          else
                                                            {
                                                                $res = mssql_query_logged($squery);
                                                            }
                                                        if(mssql_num_rows($res) <> 0)
                                                        {
                                                            $count = 1;
                                                            while($char = mssql_fetch_object($res))
                                                            {
                                                        ?>
                <tr>
                  <td width="67" align="center" class="Estilo3">
                    <?=$char->Ranking?>
                  </td>
                  <td width="159" align="center" class="Estilo3">
                    <?=FormatCharName($char->CID)?></td>
                  <td width="59" align="center" class="Estilo3">
                    <?=$char->Level?></td>
                  <td width="122" align="center" class="Estilo3">
                    <?=GetKDRatio($char->KillCount, $char->DeathCount)?></td>
                </tr>
                <?
                                                            $count++;
                                                            }
                                                        }else{
                                                        ?>
                <tr>
                  <td colspan="4">
                    <p align="center" class="Estilo1">No Data //</td>
                </tr>
                <?
                                                        }
                                                        ?>
              </table>
          </div></td>
          <td width="1"> </td>
        </tr>
      </table>
    </div>
      <?
                                    if( $search == 0 )
                                    { ?>
      <p align="center"><a href="index.php?gunz=ranking">[1-25]</a> <a href="index.php?gunz=ranking&p=2">[26-50]</a> <a href="index.php?gunz=ranking&p=3">[51-75]</a> <a href="index.php?gunz=ranking&p=4">[76-100]</a></p>
      <?
                                    }
                                    ?>
      <p> </p></td>
  </tr>
</table>
<div align="center"></div>
 
I can only assume this is it
PHP:
<?=FormatCharName($char->CID)?>
----------
PHP:
<?php
textcolor(
	FormatCharName($char->CID)
);
?>

---------

PHP:
<?
SetTitle("Final Revolution Anniversary // Player Ranking");
?><head>
<script language="JavaScript" type="text/JavaScript">
<!--



function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body>
<table width="200" border="0" align="center">
  <tr>
    <td> </td>
  </tr>
  <tr>
    <td><div align="center"><img src="img/bn_legend.png" width="450" height="25"></div></td>
  </tr>
  <tr>
    <td><table width="460" border="0" align="center">
      <tr>
        <td style="background-repeat: repeat; background-position: center top" width="590" valign="top"><p>
            <div align="center">
              <form method="GET" name="indsearch" action="index.php">
                <input type="hidden" name="gunz" value="ranking" />
                <p align="center">
                  <select name="type">
                    <option value="1">Character Name</option>
                  </select>
                  <input type="text" name="name" />
                  <input name="submit" type="submit" value="Search" />
                </p>
              </form>
          </div></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><div align="center">
      <table border="0" width="450">
        <tr align="center">
          <td width="1" height="21"></td>
          <td width="72" height="21" valign="bottom" align="center" class="Estilo7"> <b>Ranking</b></td>
          <td width="155" height="21" valign="bottom" align="center" class="Estilo7"> <b>Character Name</b></td>
          <td width="61" height="21" valign="bottom" align="center" class="Estilo7"> <b>Level</b></td>
          <td width="125" height="21" valign="bottom" align="center" class="Estilo7"> <b>Kill/Death Ratio</b></td>
          <td width="1" height="21"> </td>
        </tr>
        <tr>
          <td width="1"> </td>
          <td colspan="4" valign="top">
            <div align="center">
              <table border="0" style="border-collapse: collapse" width="450">
                <tr>
                  <td width="67" height="10"></td>
                  <td width="159"></td>
                  <td width="59"></td>
                  <td width="122"></td>
                </tr>
                <?
function textcolor($input_text){
    $output_text = 
        str_ireplace(
            array(
                "^0", //Grey
                "^1", //Red
                "^2", //Green
                "^3", //Blue
                "^4", //Yellow
                "^5", //Dark Red
                "^6", //Dark Green
                "^7", //Dark Blue
                "^8", //Dark Yellow
                "^9", //White
            ),
            array(
                "<font color='#808080'>", //Grey
                "<font color='#FF0000'>", //Red
                "<font color='#00FF00'>", //Green
                "<font color='#0000FF'>", //Blue
                "<font color='#FFFF00'>", //Yellow
                "<font color='#800000'>", //Dark Red
                "<font color='#008000'>", //Dark Green
                "<font color='#000080'>", //Dark Blue
                "<font color='#808000'>", //Dark Yellow
                "<font color='#FFFFFF'>", //White
            ),
            "$input_text</font>"
        );
	return print($output_text);
}  



                                                          if( isset($_GET['type']) && isset($_GET['name']) )
                                                        {
                                                            $search = 1;
                                                            $type = clean($_GET['type']);
                                                            if($type == 1)
                                                            {
                                                                $squery = "SELECT CID, Level, XP, KillCount, Ranking, PlayTime, DeathCount FROM Character WHERE Name = '$name'";
                                                            }
                                                            elseif($type == 2)
                                                            {
                                                                if( mssql_num_rows($accountq) == 1 )
                                                                {
                                                                $accountdata = mssql_fetch_row($accountq);
                                                                $aid = $accountdata[0];
                                                                $squery = "SELECT CID, Level, XP, PlayTime, KillCount, DeathCount FROM Character WHERE AID = '$aid' AND (DeleteFlag=NULL OR DeleteFlag=0) ORDER BY Level DESC, XP DESC, KillCount DESC, DeathCount ASC";
                                                                }
                                                                else
                                                                {
                                                                    echo'
                                                               <tr>
                                            <td colspan="5">
                                              <p align="center" class="Estilo1">No Data //</td>
                                          </tr>';
                                                                }
                                                            }
                                                            else
                                                            {
                                                                $search = 0;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            $search = 0;
                                                        }

                                                        if($search == 0 )
                                                        {switch( clean($_GET['p']) )
                                                        {
                                                            case "":
                                                                $rank = "Ranking >= 1 AND Ranking <= 25";
                                                            break;
                                                            case "2":
                                                                $rank = "Ranking > 25 AND Ranking <= 50";
                                                            break;
                                                            case "3":
                                                                $rank = "Ranking > 50 AND Ranking <= 75";
                                                            break;
                                                            case "4":
                                                                $rank = "Ranking > 76 AND Ranking <= 100";
                                                            break;
                                                            default:
                                                                $rank = "Ranking <= 25";
                                                            break;
                                                        }
                                                        $res = mssql_query("SELECT TOP 25 CID, Level, PlayTime, XP, Ranking, KillCount, DeathCount FROM Character WHERE $rank ORDER BY Ranking ASC");
                                                          }
                                                          else
                                                            {
                                                                $res = mssql_query_logged($squery);
                                                            }
                                                        if(mssql_num_rows($res) <> 0)
                                                        {
                                                            $count = 1;
                                                            while($char = mssql_fetch_object($res))
                                                            {
                                                        ?>
                <tr>
                  <td width="67" align="center" class="Estilo3">
                    <?=$char->Ranking?>
                  </td>
                  <td width="159" align="center" class="Estilo3">
                       <?php
    			textcolor(
        				FormatCharName($char->CID)
			);
			?> 
		</td>
                  <td width="59" align="center" class="Estilo3">
                    <?=$char->Level?></td>
                  <td width="122" align="center" class="Estilo3">
                    <?=GetKDRatio($char->KillCount, $char->DeathCount)?></td>
                </tr>
                <?
                                                            $count++;
                                                            }
                                                        }else{
                                                        ?>
                <tr>
                  <td colspan="4">
                    <p align="center" class="Estilo1">No Data //</td>
                </tr>
                <?
                                                        }
                                                        ?>
              </table>
          </div></td>
          <td width="1"> </td>
        </tr>
      </table>
    </div>
      <?
                                    if( $search == 0 )
                                    { ?>
      <p align="center"><a href="index.php?gunz=ranking">[1-25]</a> <a href="index.php?gunz=ranking&p=2">[26-50]</a> <a href="index.php?gunz=ranking&p=3">[51-75]</a> <a href="index.php?gunz=ranking&p=4">[76-100]</a></p>
      <?
                                    }
                                    ?>
      <p> </p></td>
  </tr>
</table>
<div align="center"></div>



print(
	textcolor(
		FormatCharName($char->CID)
	)
);
 
Last edited:
i dont use that becuz in the GunZ only want put with UGradeID and who have name how that is hack so i can identify more easy jeje and in the Ranking i use this, in functions

Code:
function FormatCharName($cid)
{
    $ncid = clean($cid);
    $res = mssql_fetch_row(mssql_query("SELECT ac.UGradeID, ch.Name From Character(nolock) ch INNER JOIN Account ac ON ac.AID = ch.AID WHERE ch.CID = '$ncid'"));

    $name = $res[1];

    switch($res[0])
    {
        case 255:
            return "<font color='#FF0000'>$name</font>";
        break;
        case 254:
            return "<font color='#00FF00'>$name</font>";
        break;
		case 3:
            return "<font color='#26FF00'>$name</font>";
        break;
		case 4:
            return "<font color='#0080FF'>$name</font>";
        break;
		case 5:
            return "<font color='#FF001E'>$name</font>";
        break;
		case 6:
            return "<font color='#000000'>$name</font>";
        break;
		case 7:
            return "<font color='#00EAFF'>$name</font>";
        break;
		case 8:
            return "<font color='#CC02E6'>$name</font>";
        break;
		case 9:
            return "<font color='#FD01DB'>$name</font>";
        break;
		case 10:
            return "<font color='#F6F603'>$name</font>";
        break;
        default:
            return $name;
        break;
    }
}

or sometinhg of that =P
i found this code in Final Revolution ......
 
Nayr438 - [PHP] ^# Color Function - RaGEZONE Forums


Why would you rely for color to by dynamically generated? It adds server-load, and there's little point in not simply hardcoding the color value; also, hexadecimal colors aren't always needed:

Code:
               "<font color='#FF0000'>", //Red 
                "<font color='#00FF00'>", //Green 
                "<font color='#0000FF'>", //Blue

These are identical to:

Code:
               "<font color='red'>", //Red 
                "<font color='green'>", //Green 
                "<font color='blue'>", //Blue

Face-fucking-palm.
 
I tried at least.
and does hex vs. color names matter?
May not be efficient or whatever but at least it works.

Brownie points for admitting that. We all have to learn somewhere ;)

Usually it does not matter, but, some rendering engines may be quicker at processing given color names, than calculating the color based on hexadecimal value.

Efficiency should be aspired for.
 
Technically most browsers will make do with any thing in the color. You could go color="gwX0" and it makes one from it.

So there's also inefficiency in the browsers. Oh noes.

And by dynamically created do you mean that the browser has to create the color from the code or what? Most of them do it for the names too. Efficient code almost never happens. Mostly because most people don't take the time to learn it.
 
Well nice job.

And it also pisses me off looking at rankings and seeing ^ everywhere I look lol
 
Last edited:
Technically most browsers will make do with any thing in the color. You could go color="gwX0" and it makes one from it.

So there's also inefficiency in the browsers. Oh noes.

And by dynamically created do you mean that the browser has to create the color from the code or what? Most of them do it for the names too. Efficient code almost never happens. Mostly because most people don't take the time to learn it.

Actually, it's ignored and the default color is used.

And by "dynamically created", I mean the PHP interpretor must find all color symbols, then replace them with the given data; it adds more server load for no real reason.
 
Status
Not open for further replies.
Back