PHP Code Conversion Small Example

Source: Internet
Author: User
  1. /*
  2. * Common coding problems
  3. *
  4. * 1. The page garbled problem:
  5. * Page garbled problem is mainly in the display font encoding and the browser display in the code is inconsistent, the browser output
  6. * The encoding is made by the page file
  7. * To control, and if your program output characters are garbled, then the program output of the font is not the same code set above, then there will be garbled
  8. * 2. The problem of garbled database
  9. * The database has a default character encoding, if you submit the character encoding and data inside the code is different, then the database display
  10. * It's going to be garbled.
  11. * (Script Academy bbs.it-home.org)
  12. * Summary: Just garbled is due to the two characters of the coding is not the same cause, then you have to find ways to make them the same
  13. *
  14. * Main points:
  15. * 1. the setting of the header
  16. * 2. Settings for database default encoding
  17. * 3. Encoding settings for the editor (sometimes this is important,)
  18. * (The best way to do this is to set all three codes to the same)
  19. *
  20. * Sometimes garbled can also be converted with some encoding conversion functions, as long as the conversion into the same code set in the inside,
  21. * Main encoding conversion function
  22. * Mb_convert_encoding (Str,to,from)
  23. * Mb_convert_encoding ("Everyone Good", "GBK", "Utf-8") (The first encoding is the purpose of the encoding to be converted, and the second is the code that you write the encoding of the editor)
  24. *
  25. * ICONV (IN,OUT,STR)
  26. * */
  27. Echo mb_convert_encoding ("good", "GBK", "Utf-8"),//In the utf-8 of the inside will be garbled, because you output is converted to GBK encoding
  28. Echo iconv ("Utf-8", "GBK", "everyone good");
  29. ?>
Copy Code
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.