Learning the Character Encoding of a File with PHP
It stumbled upon me recently when I was loading subtitles. Some subtitles are UTF-8 and some are ISO-8859-9. That's why the codes I wrote were showing one properly but not the other. So I needed to find out what character encoding the file belonged to. And I wrote a code like this;
$open = file_get_contents('test.srt');
$enc = mb_detect_encoding($open, mb_list_encodings(), true);
echo $enc; // result: UTF-8 ya da ISO-8859-9
So what did it do for me to find this? In this way, I was able to determine the character set with the header as follows;
if ($enc == "UTF-8") {
header('Content-type: text/vtt; charset=utf8');
} else {
header('Content-type: text/vtt; charset=iso-8859-9');
}
This solved my character problems. If you encounter such an error one day, you now know the solution, take it easy.
Comments
Popular Articles
Popular Tags
- #directive
- #Function
- #React
- #Class
- #centOS
- #Json
- #Text
- #API
- #URL
- #Encrypting
- #Redirect
- #Form
- #Special Characters
- #Special
- #Random
- #Generating
- #SASS
- #Version
- #Installation
- #Show
- #
- #Ajax
- #method
- #Logic For Displaying Posts
- #Key
- #DDOS
- #Default Value
- #Comment Line
- #1364 Field
- #Error
- #Abbreviation
- #QR Code Generating
- #Date
- #timeAgo
- #cURL
- #Array
- #Arrays with Key Values to String Statement
- #Short Tag
- #Vite
- #Reading Excel Files
- #Activate
- #Reading
- #Composer
- #Autoloader
- #PSR-4
- #Insert
- #Record
- #Real Time
- #Characters
- #Socket.io
There are no comments, make the firs comment