PHP echo variable and html together
<?php
$variable = 'testing';
echo <span class="label-[variable]">[variable]</span>
?>
Should be
<?php
$variable = 'testing';
echo '<span class="label-' . $variable .'">' . $variable . '</span>';
?>
If your HTML contains double quotes, then you can wrap it in single quotes:
echo '<span class="label-' . $variable . '">' . $variable . '</span>';
Additionally, you can do it inline by escaping the double quotes:
echo "<span class=\"label-$variable\">$variable</span>";
Using double quotes also allows for special characters such as \n
and \t
.
The documentation is your friend.