Php code conversion example

Source: Internet
Author: User
Php code conversion example

  1. /*
  2. * Common coding problems
  3. *
  4. * 1. page garbled characters:
  5. * The garbled page is mainly because the encoding of the display font is inconsistent with the encoding displayed in the browser, which is output by the browser.
  6. * Encoding is performed
  7. *. If the characters output in your program are garbled characters, it means that the fonts output by the program are not the same encoding as the ones set above, then garbled characters will appear.
  8. * 2. database garbled issues
  9. * The database has the default character encoding. if the encoding you submit is different from the encoding in the data,
  10. * It will also be garbled
  11. * (Script School bbs.it-home.org)
  12. * Conclusion: garbled characters are produced because the encoding of the two types of characters is different. you must try to make them the same.
  13. *
  14. * Main points:
  15. * 1. Header settings
  16. * 2. database default encoding settings
  17. * 3. encoding settings of the editor (sometimes this is important ,)
  18. * (The best way is to set the three encodings to the same)
  19. *
  20. * Sometimes garbled characters can be converted using some encoding conversion functions. You can set the same encoding,
  21. * Main encoding conversion functions
  22. * Mb_convert_encoding (str, to, from)
  23. * Mb_convert_encoding ("Hello everyone", "gbk", "UTF-8") (the first encoding is the destination encoding to be converted, and the second is the encoding you write in the code editor)
  24. *
  25. * Iconv (in, out, str)
  26. **/
  27. Echo mb_convert_encoding ("Hello everyone", "gbk", "UTF-8"); // garbled characters are generated in UTF-8, because the output is encoded into gbk.
  28. Echo iconv ("UTF-8", "gbk", "Hello everyone ");
  29. ?>

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.