Jump to content

SimpleXML problem

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
mavmak

mavmak

    Newbie

  • Members
  • Pip
  • 3 posts
Hi everybody, I am new in the forum... I have this problem:

Parse error: syntax error, unexpected ':'

Phpcode

<?php

$search_artist=$_POST["textfield4"];
$url='http://ws.audioscrobbler.com/2.0/?method=artist.getevents&artist='.$search_artist.'&api_key=b25b959554ed76058ac220b7b2e0a026';
$lfm = simplexml_load_file($url);
$name=$lfm->events->event[0]->venue->name;
$lat=$lfm->events->event[0]->venue->location->geo: point->geo:lat;
?>

XMLfile
<geo: point>
<geo:lat>36.116143</geo:lat>
<geo:long>-115.176416</geo:long>
</geo: point>


How can I get geo:lat value ;:crying:

#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
you need to do it like this: {'geo:lat'} and {'geo: point'}
$lat=$lfm->events->event[0]->venue->location->{'geo: point'}->{'geo:lat'};

__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#3
mavmak

mavmak

    Newbie

  • Members
  • Pip
  • 3 posts

Orjan said:

you need to do it like this: {'geo:lat'} and {'geo: point'}

$lat=$lfm->events->event[0]->venue->location->{'geo: point'}->{'geo:lat'};


It doesn't seem to work...

I use

echo $lfm->events->event[0]->venue->name;
echo $lfm->events->event[0]->venue->location->{'geo: point'}->{'geo:lat'};

but the output is only the name... :crying:

#4
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
you can also try

echo (string)$lfm->events->event[0]->venue->location->{'geo: point'}->{'geo:lat'};

__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#5
mavmak

mavmak

    Newbie

  • Members
  • Pip
  • 3 posts
Finally I found the solution:

$lfm = simplexml_load_file($url);
$ns = $lfm->getNamespaces(true);
$geo=$lfm->events->event[0]->venue->location->children($ns[geo]);

$lat = $geo->point->lat[0];
$long = $geo->point->long[0];

echo $lat.' | '.$long;