How can syntax errors be avoided when using CSS classes in PHP output?

To avoid syntax errors when using CSS classes in PHP output, make sure to properly escape any double quotes within the class attribute value. This can be done by using single quotes around the attribute value in the HTML output. This ensures that the PHP code generates valid HTML syntax without causing any issues.

<?php
$css_class = 'my-class';
echo '<div class="' . htmlspecialchars($css_class, ENT_QUOTES) . '">Content</div>';
?>