Problem:
You have non-UTF-8 encoded files and want to convert them to UTF-8 without disrupting their content. However, your script using standard file manipulation functions saves the files in the original encoding.
Solution:
To save files in UTF-8 format, you can use file_put_contents(). Additionally, to ensure that the file is interpreted correctly by various applications, add a Byte Order Mark (BOM) to the beginning of the file.
Code:
file_put_contents($myFile, "\xEF\xBB\xBF". $content);
Explanation:
The above is the detailed content of How to Save a File in UTF-8 Format with a BOM?. For more information, please follow other related articles on the PHP Chinese website!