You are here

public function ParserCSV::fixEncoding in Feeds 7.2

Converts encoding of input data.

Parameters

string $data: A chunk of data.

Return value

string The encoded data.

Throws

ParserCSVEncodingException Thrown when a given encoding does not match.

1 call to ParserCSV::fixEncoding()
ParserCSV::parse in libraries/ParserCSV.inc
Parse CSV files into a two dimensional array.

File

libraries/ParserCSV.inc, line 397
Contains CSV Parser.

Class

ParserCSV
Functionality to parse CSV files into a two dimensional array.

Code

public function fixEncoding($data) {
  if ($this->useMbString) {
    if (mb_check_encoding($data, $this->fromEncoding)) {
      if ($this->toEncoding != $this->fromEncoding) {

        // Convert encoding. The conversion is to UTF-8 by default to prevent
        // SQL errors.
        $data = mb_convert_encoding($data, $this->toEncoding, $this->fromEncoding);
      }
    }
    else {
      throw new ParserCSVEncodingException(t('Source file is not in %encoding encoding.', array(
        '%encoding' => $this->fromEncoding,
      )));
    }
  }
  return $data;
}