How to change the file encoding to utf8 in php: first read the file into a string through the [file_get_contents] function; then convert the encoding of the string through the iconv method; and finally write the string into the file.
Recommended: "PHP Video Tutorial"
php Convert File Encoding
$contents_before = file_get_contents($input); $contents_after = iconv('UCS-2','UTF-8',$contents_before); file_put_contents($input, $contents_after);
Be careful after processing, The file $input has been changed.
The file_get_contents() function reads the entire file into a string.
iconv — The string is converted according to the required character encoding; the
file_put_contents() function writes a string to the file.
The above is the detailed content of How to change file encoding to utf8 in php. For more information, please follow other related articles on the PHP Chinese website!