Zend Framework

Zend_Config_Xml encoding problem (utf-8 vs. iso-8859-1)

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Won't Fix
  • Affects Version/s: 1.9.5
  • Fix Version/s: None
  • Component/s: Zend_Config
  • Labels:
    None

Description

I'm not sure if this is an issue of Zend_Config, Zend_Config_Xml, the core parser itself or whatever is under the hood of those components. Here's the case:

I have a xml config file, which I used with Zend_Navigator to display a website menu. The file is encoded with ISO-8859-1 on the disk, and the headers inside the file say:
<?xml version="1.0" encoding="ISO-8859-1" ?>

In my bootstrap, I have:

protected function _initNavigation() {
	$registry = Zend_Registry::getInstance();
	$layout = $registry->get('Zend_Layout');
	$view = $layout->getView();
	$config = new Zend_Config_Xml(APPLICATION_PATH . '/config/navigation.xml', 'nav');
	$navigation = new Zend_Navigation($config);
	$view->navigation($navigation);
}

So far so good. When I tell my layout renderer to display the menu, with

echo $this->navigation()->menu();

I get garbled accents, i.e. "InÃcio" instead of "Início".

Content-Type headers are being sent out to tell the browser we're using ISO-8859-1:

<?php header('Content-Type: text/html; charset=iso-8859-1'); ?>
...
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />

If I change browser encoding to UTF-8, it displays right.

So far I've been using utf8_decode() to fix it. I believe there's something wrong with the XML parser.

Activity

Hide
jw added a comment -

I'd be interested to know if you are still having problems and whether it turned out to be an issue with Zend_Config_Xml.

Show
jw added a comment - I'd be interested to know if you are still having problems and whether it turned out to be an issue with Zend_Config_Xml.
Hide
Timo Karvinen added a comment -

As far as I can tell this is really not an issue with Zend_Config_Xml exactly.
It's a feature of SimpleXML to only return output as UTF-8 strings.

But it would be really nice if we could set an option in Zend_Config_Xml to get the configuration array output as iso-8859-1 by setting an attribute on the config object or so.

You only need to put utf8_decode($value) in two places (lines 201 and 275) on the Zend_Config_Xml-class if "output = iso-8859-1" has been set somewhere, otherwise it should work as it does now.

Show
Timo Karvinen added a comment - As far as I can tell this is really not an issue with Zend_Config_Xml exactly. It's a feature of SimpleXML to only return output as UTF-8 strings. But it would be really nice if we could set an option in Zend_Config_Xml to get the configuration array output as iso-8859-1 by setting an attribute on the config object or so. You only need to put utf8_decode($value) in two places (lines 201 and 275) on the Zend_Config_Xml-class if "output = iso-8859-1" has been set somewhere, otherwise it should work as it does now.

People

Vote (2)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: