Christoph Baudson schrieb:
Thomas Baschetti schrieb:
Hi,
while exploring http://trac.osgeo.org/mapbender/ticket/171
i got a little bit stuck.
The problem seems to in
mod_addWMSfromfilteredList_server.php
the line
$output = $json->encode($resultObj);
which fails if the database is not UTF-8 but ISO-8859-1
see http://de.php.net/manual/en/function.json-encode.php
"This function only works with UTF-8 encoded data." If you use e.g.
german umlauts in ISO you will get "Oberfl" instead of "Oberfläche".
So, converting values to UTF-8 is necessary, but when and where?
Right after retrieving the values from the database or just before
using json_encode? And are other files affected, too?
Hi Thomas,
please check the method "encode" of http/classes/class_json.php
We could make the change there...
Hope this helps
Christoph
ok,
i tried the following in http/classes/class_json.php
(see http://de.php.net/manual/de/function.json-encode.php#72450)
-------snipp----------------------
/**
* Converts incoming to UTF-8 for json_encode
*
*/
private function json_fix_charset($var)
{
if (is_array($var)) {
$new = array();
foreach ($var as $k => $v) {
$new[$this->json_fix_charset($k)] =
$this->json_fix_charset($v);
}
$var = $new;
} elseif (is_object($var)) {
$vars = get_class_vars(get_class($var));
foreach ($vars as $m => $v) {
$var->$m = $this->json_fix_charset($v);
}
} elseif (is_string($var)) {
$var = utf8_encode($var);
}
return $var;
}
/**
* Encodes an object to JSON
*/
public function encode($anObject) {
if ($this->library == JSON_PEAR) {
$pear = new Services_JSON();
$e = new mb_notice("using PEAR JSON");
return $pear->encode($anObject);
}
$e = new mb_notice("using native JSON");
return json_encode($anObject);
//return json_encode($this->json_fix_charset($anObject));
}
-------snipp----------------------
which works for Add WMS from filtered List (hooray), and
breaks "Load WMC from list" (boo), because now all is converted to UTF-8...
Hm, i have to think about this a little more...
Ciao
Thomas
--
Thomas Baschetti - Systemanalyse Geographische Informationssysteme
Hakenstraße 8D
49074 Osnabrück
Tel: 0541 25 91 90 | mobil 01577 189 25 91
E-Mail: [email protected]
www.thomas-baschetti.de
Ust-IdNr.: DE264355072
_______________________________________________
Mapbender_dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/mapbender_dev