Logo Hoinăreală Logo
Logo Hoinareala HUB Hoinăreală Logo Hoinareala Home Page hoinar Logo Hoinareala Informatică Logo Hoinareala Lupta cu cancerul Logo Hoinareala Religie Logo Hoinareala Maşini Logo Hoinareala Altele Logo Hoinareala Chat & Radio

Get opposite color text of any background color

<?php

function randomcolor()
{
    
$myrandomcolor  "#";
    for (
$i=1$i<=3$i++)
        {
            
$x rand(0,255);
            
$x dechex($x);
            
$x strtoupper($x);
            if (
strlen($x) == 1)
            {
                
$x "0".$x;
            }
            
$myrandomcolor  .= $x;
        }
    return 
$myrandomcolor;
}

$color_backgr=randomcolor();
$nrcolor_backgr=preg_replace("/[^0-9,^A-Z]/","",$color_backgr);

$nrc=hexdec($nrcolor_backgr);
$r=$nrc >> 16 0xff;
$g=$nrc >> 0xff;
$b=$nrc 0xff;

$rc=$r 0xff;
$gc=$g 0xff;
$bc=$b 0xff;

$oppositeColor=( $rc << 16 ) | ( $gc << ) | $bc;

$oppositeColor="#".substr("000000".dechex($oppositeColor),-6);

$color_text=$oppositeColor;

echo 
$color_text;

?>


Color text code: #d5bb40
Color background code: #2A44BF
Example: Test

Copyright © 2017; All right reserved Hoinăreală.