How can PHP code be properly inserted into the value attribute of an HTML element?

When inserting PHP code into the value attribute of an HTML element, it's important to properly escape the PHP code to ensure it doesn't break the HTML structure. One way to do this is by using PHP echo statements within the attribute value. This allows you to output the desired PHP variable or function result directly into the HTML attribute.

<input type="text" value="<?php echo htmlspecialchars($phpVariable); ?>">