What are some best practices for linking PHP variables to HTML elements?

When linking PHP variables to HTML elements, it is best practice to use PHP echo statements within the HTML code to output the variable values. This ensures that the PHP variables are properly displayed within the HTML elements. Additionally, it is important to sanitize the variables to prevent any security vulnerabilities.

<?php
// Define a PHP variable
$name = "John Doe";

// Output the variable within an HTML element using PHP echo
echo "<p>Hello, $name!</p>";
?>