UTF-8, which stands for "UnicodeTransformation Format, 8-bit," is a method of character encoding for Unicode, and it is the most widely used character encoding method on the web. UTF-8 represents every character in the Unicode set, but it is also compatible with standard ASCII. Many governing bodies for Internet technology require that UTF-8 be supported, and it is even becoming as popular as a standard character set in operating systems. UTF-8 is also the default character representation in the PHP programming language.
- Skill level:
- Moderately Easy
Determine the variable name of the string to be converted. Note that all variables in PHP must begin with a dollar sign ($).
Determine a new variable name for the UTF-8 encoded string. For example, if the original string was named "$my_string", you may want to name your UTF-8 encoded string "$my_string_utf8".
Pass the original string into PHP's utf8_encode() function, and set its result to the variable you named above. This is all done in one PHP statement, replacing the variable names with the correct values from Steps 1 and 2:
$my_string_utf8 = utf8_encode($my_string);
Converting a String to UTF-8
Determine the variable name of the UTF-8 encoded string to be decoded back to ISO-8859-1. ISO-8859-1 is another standard character set, but it only handles characters derived from the Latin alphabet.
Determine a new variable name for the decoded string. For example, if the original string was named "$my_string_utf8", you may want to name your ISO-8859-1 encoded string "$my_string_iso" for clarity.
Pass the UTF-8 string into PHP's utf8_decode() function, and set its result to the variable you named above. This is all done in one PHP statement, replacing the variable names with the correct values from Steps 1 and 2:
$my_string_iso = utf8_decode($my_string_iso);
Decoding a UTF-8 String
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for