title: Reading Encoded File in PHP
body: <p>I have a text file that displays as below when I open it in Sublime Text:</p>
  
  <p><a href="https://i.stack.imgur.com/7hwwp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7hwwp.png" alt="enter image description here"></a></p>
  
  <p>But when I <code>fread</code> the file and echo each line in php, I get garbled characters like this:</p>
  
  <p><a href="https://i.stack.imgur.com/2omcq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2omcq.png" alt="enter image description here"></a></p>
  
  <p>I read <a href="http://www.joelonsoftware.com/articles/Unicode.html" rel="nofollow noreferrer">Joel's post on encoding</a> and understood the basics of encoding. Also, When I do <code>mb_detect_encoding</code>, it detects the string as UTF-8. Now, I do not understand what I have to do with this information of what encoding the string is in in order to display it, or convert it, to readable characters like in the first picture. </p>
  
  <p>And why is it displaying garbled characters when it is already in UTF-8? Is php using different encoding type to read the file? Does php string have to be in UTF-8 or ASCII, or does it not matter as long as I specify what it is?</p>
  
  <p>I would really appreciate if someone can help me understanding the idea! Thanks.</p>
  
  <p>EDIT:</p>
  
  <p>Pedro Lobito and Peter's suggestions worked. </p>
  
  <pre><code>$file = file_get_contents($bl_file);
  $content = unpack("H*", $file);
  </code></pre>
  
  <p>But if someone could explain why I have to do this way, that'd still help me understanding it!</p>