title: Format output bash script in PHP's popen
body: <p>In my PHP script I'm executing a bash script with popen() and I output the response. But the response has a different encoding, and I don't know how to convert it.</p>
  
  <p>I tried to convert it to utf8 but no results. Also tried to set the locale to nl_NL.utf8.</p>
  
  <p>PHP function:</p>
  
  <pre class="lang-php prettyprint-override"><code>while (@ ob_end_flush()); // end all output buffers if any
  
  $proc = popen("$cmd 2&gt;&amp;1 ; echo Exit status : $?", 'r');
  
  $live_output     = "";
  $complete_output = "";
  
  while (!feof($proc))
  {
      $live_output     = fread($proc, 4096);
      $complete_output = $complete_output . $live_output;
      echo "$live_output";
      @ flush();
  }
  
  pclose($proc);
  </code></pre>
  
  <p>Example response:</p>
  
  <pre><code>[2K[1A[2K[G
  [2K[1A[2K[G⠋ load plugins
  [2K[1A[2K[Gsuccess load plugins - 0.975 s
  ⠋ load plugins
  </code></pre>
  
  <p>This should be just:</p>
  
  <pre><code>success load plugins - 0.975 s
  </code></pre>
  
  <p>The ⠋ thing is a loader which is moving. Could that be the problem? Or are these characters the colorcode of the line?</p>