1

I need to detect these encodings in a file :

  • UTF-8 (with/without BOM)
  • UTF-7 (I don't know about whether it has BOM)
  • UTF-16 LE/BE (always with BOM)
  • UTF-32 (I don't know about whether it has BOM)
  • Windows-**** (like Windows-1252)

mb_detect_encoding on the file content doesn't work.

Green Black
  • 5,037
  • 1
  • 17
  • 29
  • Why `mb_detect_encoding` doesn't work to files? What about to use `file_get_contents` and check ancoding then? – ozahorulia Feb 26 '13 at 22:03
  • 2
    Maybe it doesn't work when file doesn't start with a BOM. Actually, there's no reliable method to determine a string encoding without BOM. – berty Feb 26 '13 at 22:06
  • Maybe add some more detail about your situation? Why do you need to autodetect this, where does the content come from? Is there no way for the content source to specify the encoding? – Pekka Feb 26 '13 at 22:20
  • *"`mb_detect_encoding` on the file content doesn't work."*, this may sound glib, but I have to check: you're supposed to pass the function a string, not an array returned by `file` or a resource returned by `fopen`. – Asad Saeeduddin Feb 26 '13 at 22:22
  • See my answer here http://stackoverflow.com/a/15100592/22470 it has an additional check beside the poor mb_detect_encoding(). – powtac Feb 26 '13 at 22:30

0 Answers0