Reputation: 13567
I would like to style a printf line.
printf("- %d ". $maand ." & %d " . $dag , $months, $days);
Lets say i want this line to be red as output. How can i accomplish this? I think it needs to be something like this.
printf("<font style="color:red;">- %d ". $maand ." & %d " . $dag , $months, $days"</font>");
the answer of martincarlin87 seems to work but i cant make it work when im using two printf statements and want to style one of them like so:
<?(strtotime($date1) > strtotime($date2)) ? `printf("%d " . $maand . " & %d " . $dag , $months, $days) : '<div class="red">'
<?php printf("- %d ". $maand ." & %d " . $dag , $months, $days); ?>
'</div>'?>
Upvotes: 0
Views: 4681
Reputation:
This is how I did it :)
PHP:
<?php
$val1 = "Hello ";
$val2 = "World!";
printf('%s %s %s %s', $val1, '<span class="green">', $val2, '</span>');
?>
CSS:
.green {
color: #8AD17A; //green
}
Output:
hello world text with "world" changed to the color green
Upvotes: 1
Reputation: 11042
HTML
<div class="red">
<?php printf("- %d ". $maand ." & %d " . $dag , $months, $days); ?>
</div>
CSS
.red {
color: red;
}
The font
tag is deprecated in HTML5.
edit
Try this for your ternary if
:
<?(strtotime($date1) > strtotime($date2)) ? printf("%d " . $maand . " & %d " . $dag , $months, $days) : printf("<div class=\"red\">- %d ". $maand ." & %d " . $dag . "</div>" , $months, $days) . '' ?>
Upvotes: 2
Reputation: 1100
No there is no way. But you can use sprintf() which return string.
echo '<font style="color:red;">'.sprintf("- %d ". $maand ." & %d " . $dag , $months, $days).'</font>';
Upvotes: 0