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 ;
You appear to have a space after the colon. I don't think a colon is valid in a member variable name either. Try just referencing ->point->lat instead, as the geo: part is a namespace. Or use DomDocument and DomXPath instead of simplexml.
This isnt valid XML. You will need to correct the XML in order to process it correctly. You are also not referencing the name spaces correctly. You might want to refer to something like the following in order to understand namespaces and attributes correctly; http://www.sitepoint.com/blogs/2005/10/20/simplexml-and-namespaces/ OR..... if it is just the LAT you are after you can do something like; preg_match("|<geo:lat>(.+?)</geo:lat>|i", $your_xml_feed, $match); print $match[1]; PHP: OUTPUT: 36.116143
the space before colone is because : P= (emoticon appears)... for that reason I leave a space so you can understand the code. The XML file is this location ws.audioscrobbler.com/2.0/?method=artist.getevents&artist=madonna&api_key=b25b959554ed76058ac220b7b2e0a026