Reputation: 981
I have a php page with html and php in it. I have the following code:
for ($x = 0; $x <= 100; $x++) {
$result = convertTemp($x);
$tempdesc = getTempName($x);
$textcolor = "blue";
echo ($x . " degrees F is equal to " . round($result, 1) . " C, which is " . '<span id="<?php $textcolor ?>" >' . $tempdesc . '</span>' ."<br/>\n");
}
I would like to have the variable tempdesc
echo in different colors based on the $textcolor
variable above. For now I have it set to "blue" since I have an id set to blue in my css so they should match up and the word should be echoed in blue but the text is not changing color.
Upvotes: 1
Views: 1214
Reputation: 57
how about using sass ? u can use variable as color or anything in it!
Upvotes: 0
Reputation: 43
Perhaps what you want is to change the inline style.
for ($x = 0; $x <= 100; $x++) {
$result = convertTemp($x);
$tempdesc = getTempName($x);
$textcolor = "blue";
echo ("{$x} degrees F is equal to {round($result, 1)} C, which is " .
'<span style="color:{$textcolor}">' . "{$tempdesc}" . '</span>' ."<br/>\n");
}
Make sure to use the curly braces around the variable.
Upvotes: 0
Reputation: 11
you did not have any variable ($blue)
please replace only this line
<span style="color:'.$textcolor.'" >
Upvotes: 0
Reputation: 5223
<?php
and ?>
should be removed.$textcolor
, not $blue
.Try:
echo ($x . " degrees F is equal to " . round($result, 1) . " C, which is " . '<span id="' . $textcolor . '" >' . $tempdesc . '</span>' ."<br/>\n");
Upvotes: 2