What is the purpose of utf8_encode() and when should it be used in PHP?

The utf8_encode() function in PHP is used to convert a string from ISO-8859-1 encoding to UTF-8 encoding. This function should be used when you have a string that is encoded in ISO-8859-1 and you need to convert it to UTF-8 to ensure proper handling of characters from different languages.

$string = "Hello, world!";
$utf8_string = utf8_encode($string);
echo $utf8_string;