What are the potential issues with using document.write in PHP code for embedding external content?

Using document.write in PHP code for embedding external content can cause issues with the order of execution and can lead to unexpected behavior. It is recommended to use PHP functions like echo or print to output content instead. This ensures proper handling of the content and avoids conflicts with other scripts on the page.

<?php
// Incorrect way using document.write
echo "<script>document.write('<p>External content</p>');</script>";

// Correct way using echo
echo "<p>External content</p>";
?>