0

I have the code and I need to replace hex colors code to real color in PHP.

    <?php
$host = "localhost";
$username = "root";
$password = "passhere";
$dbName = "userpanel";

$con = new mysqli($host,$username,$password,$dbName);

echo '
<!DOCTYPE html>
<html>
<body>
    <div class="header"> 
    RANKINGBOARD BRASIL RACING
    </div>
    <div class="table">
        <table border="1">
            <tr class="title" align="center">
                <td>Ranking</td>
                <td>Nome</td>
                <td>Pontos</td>
                <td>Cash</td>
                <td>Mapas Jogados</td>
            </tr>
';
$getAccountData = "SELECT * FROM tableUserpanel order by CAST(points as SIGNED) desc";
$i =1;
$result= mysqli_query($con,$getAccountData);
while ( $dataMTA = mysqli_fetch_array($result,MYSQLI_ASSOC)) 
{
    echo '  
        <tr align="center">
            <td>'.$i++.'</td>
            <td>'.$dataMTA["playerName"].'</td>
            <td>'.$dataMTA["points"].'</td>
            <td>'.$dataMTA["cash"].'</td>
            <td>'.$dataMTA["mapsPlayed"].'</td>
        </tr> 

    ';
}
echo '      
        </table>
    </div>
</body>
</html>
';

?>

When the PHP query the database, playerName comes with HEX colors like |#Ly#FFFFFFca#0080ffN^ ... I need to convert the hex colors to <span style='color:HEX-GOES-HERE'>playerName here</span>, how can I do that? I'm trying for a few days.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • 5
    You should _not_ echo all of your HTML via PHP. Instead, you should switch out of PHP (`?>`) when displaying HTML. – GrumpyCrouton Dec 14 '17 at 14:26
  • Or of course move to a template library like Twig. – Nigel Ren Dec 14 '17 at 14:29
  • 3
    What about getting the hex code from whatever variable it was selected to through a regular expression and writing the code out? From my point of view, something like `|#Ly#FFFFFFca#0080ffN^` does not look like a color code – Nico Haase Dec 14 '17 at 14:30
  • In your example there are two color codes. #FFFFFF and #0080ff. If "Ly" and "ca" and "N" at the end are always present, you could use regular expression in preg_match the color codes from the string. – Ákos Nikházy Dec 14 '17 at 14:37
  • I just need to convert Hex color codes in http://forum.mta.ninja/index.php?/ranking.php/ to real colors, this info comes in a MYSQL query – Emanuel Bernardes Dec 14 '17 at 14:51
  • 1
    @ÁkosNikházy - Looks more like if a hex number follows a hash, then it's a colour code that affects all following characters until the end of the name or the next colour change. Some names have 0 #s, others have several changes of colour within them.I suspect "you're doing it wrong" would be the response to being told someone was doing this task with RegEx. Example names include: `SupremeDugong75, AWP|Ghost_nigth, #000000Adam, #ffffff*Cor#0000fftana, #8b0000~#666666Mcnunes` – enhzflep Dec 14 '17 at 15:09

0 Answers0