How-to articles, tricks, and solutions about UTF-8
error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
Here is an example of how to handle a UnicodeDecodeError caused by an invalid start byte:
file_get_contents() Breaks Up UTF-8 Characters
The file_get_contents() function in PHP is used to read the contents of a file into a string.
Getting â€™ instead of an apostrophe(') in PHP
This can occur if your PHP code is using the ISO-8859-1 character set instead of UTF-8.
How can I write a file in UTF-8 format?
To write a file in UTF-8 encoding with PHP, you can use the fopen, fwrite, and fclose functions.
How to decode Unicode escape sequences like "\u00ed" to proper UTF-8 encoded characters?
In PHP, you can use the utf8_decode() function to decode a string that contains Unicode escape sequences.
How to remove all non printable characters in a string?
To remove all non-printable characters in a string in PHP, you can use the preg_replace function with a regular expression pattern that matches non-printable characters.
How to Set HTTP Header to UTF-8 in PHP
If you want to learn how to set the HTTP header to UTF-8 in PHP, then read this snippet, examine and run the examples, that are demonstrated in it.
Setting the default Java character encoding
To set the default character encoding for the Java Virtual Machine (JVM), you can use the -Dfile.encoding option when starting the JVM.
Unicode (UTF-8) reading and writing to files in Python
To read a file in Unicode (UTF-8) encoding in Python, you can use the built-in open() function, specifying the encoding as "utf-8".