title: Detect file encoding in PHP without loading the whole file in memory
body: <p>I want to read and process large (several hundred MB) files using PHP.</p>
  
  <p>The files can be UTF-8 (with or without BOM) or ISO-8859-1 encoded.</p>
  
  <p>Considering the size, the file needs to be streamed. The standard <code>mb_detect_encoding()</code> function requires the entire file to be loaded.</p>
  
  <p>Is there any way to detect whether a file is UTF-8 or ISO-8859-1 encoded (or, if possible, encoded some other way) without loading the entire file in memory?</p>