[gelöst]SimpleXML in Drupal7
am 23.08.2012 - 15:26 Uhr in
Hallo Drupalfreunde,
ich hab derzeit ein Problem mit SimpleXML in drupal 7 und zwar ich hab diese varable definiert
<?php
$wetter['stadt'] = $api->weather->forecast_information->city->attributes->data;
?>und ich bekomme von drupal folgende Meldung
<?php
Notice: Trying to get property of non-object in mm_weather_admin() (line 39 of C:....\drupal\sites\all\modules\custom\googlewetter\mm_weather.module). =>
?>obwohl es dieses Object wie ihr hier sehen könnt gibt:
<?php
SimpleXMLElement Object
(
[@attributes] => Array
(
[version] => 1
)
[weather] => SimpleXMLElement Object
(
[@attributes] => Array
(
[module_id] => 0
[tab_id] => 0
[mobile_row] => 0
[mobile_zipped] => 1
[row] => 0
[section] => 0
)
[forecast_information] => SimpleXMLElement Object
(
[city] => SimpleXMLElement Object
(
[@attributes] => Array
(
[data] => Berlin, Berlin
)
)
.........
?>ich hab es auch schon mit attributes()-data versucht aber das zwingt drupal ganz in die Knie. Ich würde mich über jeden tipp freuen :-)
lg Th3o2211
- Anmelden oder Registrieren um Kommentare zu schreiben

th3o2211 schrieb <?php
am 23.08.2012 - 18:00 Uhr
<?php
$wetter['stadt'] = $api->weather->forecast_information->city->attributes->data;
?>
und ich bekomme von drupal folgende Meldung
<?php
Notice: Trying to get property of non-object in mm_weather_admin() (line 39 of C:....\drupal\sites\all\modules\custom\googlewetter\mm_weather.module). =>
?>
hi
data ist ein array kein object
daher
<?php
$wetter['stadt'] = $api->weather->forecast_information->city->attributes['data'];
?>
grüße
Habs Probiert funktioniert nicht
am 24.08.2012 - 07:58 Uhr
Hallo ich habs gestern noch ausprobiert und es funktioniert nicht.
<?php
$wetter['stadt'] = $api->weather->forecast_information->city->attributes['data'];
?>
warscheinlich liegt es aber jetzt an meinem website aufruf:#
<?php
$api = simplexml_load_string(utf8_encode(file_get_contents("http://www.google.com/ig/api?weather=".$station")));
?>
hier der warning:
<?php
Warning: simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]: Entity: line 1: parser error : Start tag expected, '<' not found in simplexml_load_string() (line 37 of C:\....\drupal\sites\all\modules\custom\googlewetter\mm_weather.module). =>
?>
Der Start Tag wird erwartet aber wie binde ich den hier ein? oder was genau ist mein Fehler ?
Schau dir mal das folgende
am 24.08.2012 - 08:02 Uhr
Schau dir mal das folgende Posting auf stackoverflow.com an - dort wird das Problem recht gut erklärt:
http://stackoverflow.com/questions/2899274/php-simplexml-why-does-simple...
Das Problem liegt wohl daran, dass du das Charset direkt mit im Aufruf übergeben musst.
Ein Beispiel:
<?php$url = "http://www.google.com/ig/api?weather=Bremen&hl=de&oe=utf-8";
$load_xml = simplexml_load_string(file_get_contents($url));
echo "<pre>";
print_r($load_xml);
echo "</pre>";
?>
Dies liefert die Daten problemlos - auch ohne das iconv-Konvertierung, wie im Thread von stackoverflow angesprochen. Wichtig ist der zusätzliche Parameter oe=utf-8.
SteffenR
Ok vielen dank !!!
am 24.08.2012 - 08:28 Uhr
Auf sowas wäre ich nie gekommen vorallem weil ich gedacht habe, dass ich ja schon alles auf ut8-encodiert hatte. Vielen dank an dich SteffenR :-)