How to prevent weird characters from showing up in web pages

前端 未结 4 1266
天涯浪人
天涯浪人 2021-01-23 07:36

Often when outputting strings from a database onto a webpage, special characters get displayed as some other weird characters (in my example, an em-dash gets tu

相关标签:
4条回答
  • 2021-01-23 08:01

    Mojibake - This is the classic case of

    • The bytes you have in the client are correctly encoded in utf8.
    • You connected with SET NAMES latin1 (or set_charset('latin1') or ...), probably by default. (It should have been utf8.)
    • The column in the table was declared CHARACTER SET latin1. (Or possibly it was inherited from the table/database.) (It should have been utf8.)
    0 讨论(0)
  • 2021-01-23 08:10

    in your html view page use

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    

    and if you are inserting some other language character in place of english than make that column utf8-general-ci

    0 讨论(0)
  • 2021-01-23 08:11

    You can try this.Use following php inbuilt function to avoid those characters on given string. In your case, data from database.

    html_entity_decode($given_string,ENT_QUOTES, "ISO-8859-1");
    
    0 讨论(0)
  • 2021-01-23 08:26

    On top of your page in header tag use the below code:

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
    0 讨论(0)
提交回复
热议问题