I'm writing function that returns document in utf-8 by default, by if you provide special parameter it will return content in utf-16le. I started to write unit test for this function and what I don't understand is how to check if encoding is "utf-8" or "utf-16le". I've tried mb_detect_encoding but it returns false even in this code snippet:
$utf16Doc = mb_convert_encoding($doc, "utf-16le", "utf8");
$test = mb_detect_encoding($utf16Doc, "utf-16le");
var_dump($test);
Appreciate any ideas how to check in test that encoding is utf-16le and not utf-8.
A simple way to detect UTF-8/16/32 of file by its BOM (not work with string or file without BOM)
So now you can try like this,
Clearly Stated : This is not my own written answer. I just found it on php.net official site under
mb_detect_encodingby a user http://php.net/manual/en/function.mb-detect-encoding.php#68607 . Hope this will help you somehow