What are the potential pitfalls of executing PHP commands within an echo statement?

Executing PHP commands within an echo statement can lead to security vulnerabilities, as it allows for potential code injection attacks. To solve this issue, it is recommended to avoid mixing PHP logic with HTML output directly within an echo statement. Instead, separate PHP logic from HTML output by closing the PHP tag before the HTML output and reopening it after.

<?php
// Avoid executing PHP commands within an echo statement
$name = "John";
// Instead, separate PHP logic from HTML output
?>
<p>Welcome, <?php echo htmlspecialchars($name); ?></p>