Magento export csv conver chinese utf8 error

		/**
		 * Write item data to csv export file
		 *
		 * @param Varien_Object $item
		 * @param Varien_Io_File $adapter
		 */
		function _exportCsvItem(Varien_Object $item, Varien_Io_File $adapter)
		{
			$row = array();
			foreach ($this->_columns as $column) {
				if (!$column->getIsSystem()) {
					$row[] = $column->getRowFieldExport($item);
				}
			}
			$row = $this->d_encodeUTF8($row);
			$adapter->streamWriteCsv($row);
		}
		
		 function d_encodeUTF8($array){
			//循环数组将所有元素值变成GBK的
			foreach($array as $key=>$value){
				$array[$key] = !is_array($value)?iconv("UTF-8","GBK//ignore",$value):$this->d_encodeUTF8($array[$key]);
			}
			 
			return $array;
		}
		
		/**
		 * Retrieve Headers row array for Export
		 *
		 * @return array
		 */
		 function _getExportHeaders()
		{
			$row = array();
			foreach ($this->_columns as $column) {
				if (!$column->getIsSystem()) {
					$row[] = $column->getExportHeader();
				}
			}
			$row = $this->d_encodeUTF8($row);
			return $row;
		}
		
		/**
		 * Retrieve Totals row array for Export
		 *
		 * @return array
		 */
		 function _getExportTotals()
		{
			$totals = $this->getTotals();
			$row    = array();
			foreach ($this->_columns as $column) {
				if (!$column->getIsSystem()) {
					$row[] = ($column->hasTotalsLabel()) ? $column->getTotalsLabel() : $column->getRowFieldExport($totals);
				}
			}
			$row = $this->d_encodeUTF8($row);
			return $row;
		}

 

你可能感兴趣的:(Magento,php)