I need to set a div's background colour using PHP. Here's what I'm doing at the moment:
<div class="box" style="background-color:"<?php echo $permacolour; ?>"">
However, this isn't working. What am I doing wrong?
Thanks
<div class="box" style="background-color:<?=$permacolour?>">
quotes do not belong to PHP syntax. PHP tags are <?, <?php and ?> only
<?php ?> is a perfectly acceptable syntax for this, OP doesn't have to use <?= ?> - it's the quotes, not the PHP tags, that are the problem.<?= in this example is a short hand way of writing <?php echoTo be near your original post, here's the correct way :
<div class="box" style="background-color: <?php echo $permacolour; ?>">
The problem is that you were writing the background color surrounded by double quotes. The result would have been like
<div class="box" style="background-color:"red"">
instead of
<div class="box" style="background-color: red">
So just remove the double quotes between the value you are good to go.
Of course, this suppose you defined $permacolour or you made sure the value of $permacolour is sanitized and filtered if inputed by a user.
The answer of @your-common-sense is based on the shorthand syntax that is not always activated on hosted servers.
<?= will always be available, regardless of the short_tag setting