How can HTML tags in the fetched data affect the display in PHP?

When fetching data from a database or external source in PHP, HTML tags within the fetched data can affect the display by causing unintended formatting or even security vulnerabilities such as cross-site scripting (XSS) attacks. To prevent this, you can use the PHP `htmlspecialchars()` function to escape special characters and prevent the browser from interpreting them as HTML tags.

// Fetch data from database or external source
$fetchedData = "<p>This is some fetched data with <strong>HTML tags</strong></p>";

// Display fetched data while escaping HTML tags
echo htmlspecialchars($fetchedData);