What is the best practice for outputting HTML tags using echo in PHP?

When outputting HTML tags using echo in PHP, it is best practice to enclose the HTML tags within double quotes to ensure proper parsing and readability. This helps prevent syntax errors and makes the code easier to maintain. Additionally, it is important to properly escape any dynamic content to prevent cross-site scripting vulnerabilities.

<?php
// Example of outputting HTML tags using echo in PHP
$dynamic_content = "<script>alert('XSS attack')</script>";

// Enclose HTML tags within double quotes and escape dynamic content
echo "<div>" . htmlspecialchars($dynamic_content) . "</div>";
?>