• <?php
    $target = mktime(0,0,0,4,7,2011);
    $today = time();
    $difference = ($target-$today);
    $days = (int)($difference/86400);
    
    if ((date('m') == 4) && (date('d') == 7))
    {
    print "<h2>Game On!</h2>";
    }
    else
    {
    print "<h2>$days days to go!</h2>";
    }
    ?>

    I have the following code which works fine – how do I add html code to make the $days in a red font?

Viewing 4 replies - 1 through 4 (of 4 total)
  • wrap it in a span either with a css class or an inline style?

    print "<h2><span class="red_days">$days</span> days to go!</h2>";

    then in style.css:
    h2.red_days { color: red; }

    or

    print "<h2><span style="color: red;">$days</span> days to go!</h2>";
    Thread Starter sanstepsan

    (@sanstepsan)

    Alchymyth
    I tried your second option but as soon as the span is inserted the code fails to show anything at all.
    Could it be because the code is within the PHP Code widget?

    my bad – i need to pay more attention to the quotation marks:

    print "<h2><span style='color: red;'>$days</span> days to go!</h2>";

    or

    print "<h2><span class='red_days'>$days</span> days to go!</h2>";

    Thread Starter sanstepsan

    (@sanstepsan)

    Alchymyth

    Single quotes made all the difference.

    Don’t know why but many thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘php code widget’ is closed to new replies.