What are the best practices for creating popups with dynamic content using PHP?

When creating popups with dynamic content using PHP, it is important to separate the PHP logic from the HTML markup to maintain clean and readable code. One way to achieve this is by using PHP to fetch the dynamic content from a database or external source, then injecting it into the HTML markup before displaying the popup.

// Fetch dynamic content from a database or external source
$dynamic_content = "This is the dynamic content for the popup.";

// HTML markup for the popup with dynamic content
$popup_markup = '<div class="popup">
                    <p>' . $dynamic_content . '</p>
                </div>';

// Output the popup markup
echo $popup_markup;