Created
March 8, 2024 14:10
-
-
Save gabrielbarros/8a21b98790c4b45661221affa051ea02 to your computer and use it in GitHub Desktop.
Convert from ISO-8859-1 to UTF-8 and vice-versa; test if it's valid UTF-8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ISO-8859-1 → UTF-8 | |
function latin1ToUtf8(string $str): string | |
{ | |
return iconv('ISO-8859-1', 'UTF-8', $str); | |
} | |
// UTF-8 → ISO-8859-1 | |
function utf8ToLatin1(string $str): string | |
{ | |
return iconv('UTF-8', 'ISO-8859-1', $str); | |
} | |
function isValidUtf8(string $str): bool | |
{ | |
return mb_check_encoding($str, 'UTF-8'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment