Example #1
0
 /**
  * Detect current file encoding if ForceEncodingDetection is set to true or encoding parameter is null
  */
 protected function detectEncoding()
 {
     $this->detectedEncoding = $this->dialect->getEncoding();
     if ($this->isFileOpened() && ($this->dialect->getForceEncodingDetection() || empty($this->detectedEncoding))) {
         //only read the 100 first lines to detect encoding to improve performance
         $text = '';
         $line = 0;
         while (!feof($this->getFileHandler()) && $line <= 100) {
             $text .= fgets($this->getFileHandler());
             $line++;
         }
         if ($text !== false) {
             $this->detectedEncoding = Converter::detectEncoding($text, $this->dialect->getEncoding());
         }
     }
 }