dynamic rgb value not working

Posted on 2012-08-12
Last Modified: 2012-08-12
I have the following code:

echo '<td bgcolor="rgb(255, '.(255-$count_ac).','.(255-$count_ac).')">&nbsp;</td>';

----- $count_ac is a simple variable that house a number -----

after processing, it presents properly like the following:

<td bgcolor="rgb(255, 248,248)">

But the color displayed is a dark green -- it should be light red (pink)
Question by:edavo
    LVL 30

    Accepted Solution

    As W3C says "The bgcolor attribute of <td> is not supported in HTML 4.01 Strict / XHTML 1.0 Strict DTD." so check your DOCTYPE definition.

    LVL 107

    Assisted Solution

    by:Ray Paseur
    You may still be able to get away with using something like this (obviously untested code)...  But the correct way to handle this is to use style sheets.

    $r  = dechex(255);
    $g  = dechex(255 - $count_ac);
    $b  = dechex(255 - $count_ac);
    $bg = '#' . $r . $g . $b;
    $st = 'span style="background-color:' $bg . '"';
    $td = "<td $st>&nbsp;</td>";
    echo $td;

    Open in new window

    LVL 53

    Assisted Solution

    Why in the world would you use an obsolete property like bgcolor instead of styling it with:
    echo '<td style="background-color:rgb(255,' . 255-$count_ac.','.255-$count_ac.')">&nbsp;</td>';

    Then at least it would work consistently in virtually all browsers that have been manufactured in the last 10 years. Even as far back as IE4.  and everything in the future.


    Author Closing Comment

    Thats what I resorted too - I used a class for each counter - Thank You...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
    So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now