How to fix encoding issues

Most productfeeds are UTF-8 encoded.


Some, csv, feeds might be Windows-1252 or ISO-8859-1 encoded. 

Sometimes , csv or xml, file contains text that is double encoded.

In all situations, the text might appear garbled on your site. Mostly only everything that is special like the euro-sign, €, and accented characters.

The character encoding can be corrected using a callback function.


function iso2utf8_cb(&$item){
   foreach ($item as $k => $v ) {
      if ( ! is_array($v) ) {
        #utf8_decode is deprecated in php > 8.1
        # use mb_convert_encoding, iconv, inlt or a polyfil if your system does not support utf8_decode

        $item[$k]=mb_convert_encoding($v, 'UTF-8', 'ISO-8859-1');