What's the difference between UTF-8 and UTF-8 without BOM?

前端 未结 21 1429
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 05:45

What\'s different between UTF-8 and UTF-8 without a BOM? Which is better?

21条回答
  •  忘了有多久
    2020-11-21 06:01

    When you want to display information encoded in UTF-8 you may not face problems. Declare for example an HTML document as UTF-8 and you will have everything displayed in your browser that is contained in the body of the document.

    But this is not the case when we have text, CSV and XML files, either on Windows or Linux.

    For example, a text file in Windows or Linux, one of the easiest things imaginable, it is not (usually) UTF-8.

    Save it as XML and declare it as UTF-8:

    
    

    It will not display (it will not be be read) correctly, even if it's declared as UTF-8.

    I had a string of data containing French letters, that needed to be saved as XML for syndication. Without creating a UTF-8 file from the very beginning (changing options in IDE and "Create New File") or adding the BOM at the beginning of the file

    $file="\xEF\xBB\xBF".$string;
    

    I was not able to save the French letters in an XML file.

提交回复
热议问题