How to Convert a PHP String to UTF-8

Written by rob senn
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Convert a PHP String to UTF-8
UTF-8 can represent all Unicode characters. (BananaStock/BananaStock/Getty Images)

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

Other People Are Reading

Instructions

    Converting a String to UTF-8

  1. 1

    Determine the variable name of the string to be converted. Note that all variables in PHP must begin with a dollar sign ($).

  2. 2

    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".

  3. 3

    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);

    Decoding a UTF-8 String

  1. 1

    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.

  2. 2

    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.

  3. 3

    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);

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.