How do I remove  from the beginning of a file?

前端 未结 23 1035
攒了一身酷
攒了一身酷 2020-11-22 06:21

I have a CSS file that looks fine when I open it using gedit, but when it\'s read by PHP (to merge all the CSS files into one), this CSS has the following characters prepend

相关标签:
23条回答
  • 2020-11-22 06:59

    If you need to be able to remove the BOM from UTF-8 encoded files, you first need to get hold of an editor that is aware of them.

    I personally use E Text Editor.

    In the bottom right, there are options for character encoding, including the BOM tag. Load your file, deselect Byte Order Marker if it is selected, resave, and it should be done.

    Alt text http://oth4.com/encoding.png

    E is not free, but there is a free trial, and it is an excellent editor (limited TextMate compatibility).

    0 讨论(0)
  • 2020-11-22 06:59

    Check on your index.php, find "... charset=iso-8859-1" and replace it with "... charset=utf-8".

    Maybe it'll work.

    0 讨论(0)
  • 2020-11-22 07:01

    grep -rl $'\xEF\xBB\xBF' * | xargs vim -e -c 'argdo set fileencoding=utf-8|set encoding=utf-8| set nobomb| wq'

    0 讨论(0)
  • 2020-11-22 07:01

    Use Total Commander to search for all BOMed files:

    Elegant way to search for UTF-8 files with BOM?

    • Open these files in some proper editor (that recognizes BOM) like Eclipse.

    • Change the file's encoding to ISO (right click, properties).

    • Cut  from the beginning of the file, save

    • Change the file's encoding back to UTF-8

    ...and do not even think about using n...d again!

    0 讨论(0)
  • 2020-11-22 07:02

    You can use

    vim -e -c 'argdo set fileencoding=utf-8|set encoding=utf-8| set nobomb| wq'
    

    Replacing with awk seems to work, but it is not in place.

    0 讨论(0)
提交回复
热议问题