What PHP function can be used to convert special characters like umlauts to their HTML entity form?

When dealing with special characters like umlauts in PHP, it's important to convert them to their HTML entity form to ensure proper display in web applications. This can be achieved using the htmlentities() function in PHP. This function converts special characters to their corresponding HTML entities, allowing them to be displayed correctly in web pages.

$text = "Möller";
$encoded_text = htmlentities($text, ENT_QUOTES, 'UTF-8');
echo $encoded_text; // Output: Möller