How can I ensure that UTF-8 characters, such as umlauts, are displayed correctly in an RSS feed using PHP?

To ensure that UTF-8 characters, such as umlauts, are displayed correctly in an RSS feed using PHP, you need to set the appropriate content type header and encode the feed content using utf8_encode() function.

<?php
header('Content-Type: text/xml; charset=utf-8');

$xml = '<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
    <channel>
        <title>Example RSS Feed</title>
        <description>An example RSS feed with UTF-8 characters</description>
        <link>http://www.example.com</link>
        <item>
            <title>' . utf8_encode('Title with ümlauts') . '</title>
            <description>' . utf8_encode('Description with ümlauts') . '</description>
            <link>http://www.example.com/item1</link>
        </item>
    </channel>
</rss>';

echo $xml;
?>