Re: CSS and variables
| From: | LinuxManMikeC | Date: | Fri, 20 Nov 2009 16:38:30 +0000 |
| Subject: | Re: CSS and variables | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-299973@lists.php.net to get a copy of this message | ||
On Fri, Nov 20, 2009 at 9:12 AM, Phil Matt <admin@philmatt.com> wrote:
> De-lurking here.
>
> I'm trying, with no success, to use some CSS styling on my PHP output.
>
> Here's the code I want to style:
>
> echo '<tr><td
> class="spacer">'.$row[0].'</td><td>'.$row[1].'</td>
>
> I want to use a CSS style for the second <td> cell, picking up the style
> from the value of a variable. I tried this:
>
> $newcolor = "color: red";
>
> <td style= "<? echo($newcolor): ?>">'.$row[1].'</td>
>
> But it doesn't work. No problem with th "spacer" class, works fine. I just
> can't get the syntax for pulling a CSS style from a PHP var.
>
> TIA for your help!
>
You can't use PHP tags inside a string. You just need to concatenate
the variable into the string you're echoing.
echo '<tr><td class="spacer">'.$row[0].'</td><td
style="'.$newcolor.'">'.$row[1].'</td>';
PHP tags may only contain PHP statements. You can't nest additional
PHP tags within. They won't be evaluated.