title: PHP stops working in a loop of binary string after 0x03 End of Text
body: <p>I'm reading a binary file and trying to echo its content escaping all control characters:</p>
  
  <pre><code>$size    = filesize($filename);
  $handle  = fopen($filename, "rb");
  $content = utf8_encode_escape(fread($handle, $bytes));
  
  function utf8_encode_escape ($string) {
  
      $encoded = str_split(utf8_encode($string));
      $escaped = "";
  
      foreach ($encoded as $char) {
          $code = ord($char);
          echo $code . " ";
  
          if ($code &lt;= 32) {
              $escaped .= unichr(9216 + $code);
          }
          else if ($code == 127) {
              $escaped .= unichr(9249);
          }
          else {
              $escaped .= chr($code);
          }
      }
  
      return $escaped;
  }
  
  function unichr($u) {
      return mb_convert_encoding('&amp;#' . intval($u) . ';', 'UTF-8', 'HTML-ENTITIES');
  }
  </code></pre>
  
  <p><code>$content</code> is supposed to be a string with all control characters replaced by Unicode Symbol For (e.g Symbol for End of Transmission: ␄), however the loop and the script stops without error after the <code>0x00</code> byte. The file I'm reading is conhost.exe:</p>
  
  <p><a href="https://i.stack.imgur.com/CgJim.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CgJim.png" alt="enter image description here"></a></p>
  
  <p>The <code>echo $code . " ";</code> displays the following sequence: <code>77 90 144 0</code>, means that the script stops at the <code>0x03</code> byte -- End of Text. Is there any reason behind this, and how do I fix it?</p>