tqla Posted June 11, 2012 Share Posted June 11, 2012 How do I echo a single value on a SimpleXMLElement Object? For example "Tooltip Text 2". SimpleXMLElement Object ( [pix] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [pic] => image1.png [alt] => Tooltip Text 1 [desc] => Content 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [pic] => image2.png [alt] => Tooltip Text 2 [desc] => Content 2 ) ) ) ) Thanks. Link to comment https://forums.phpfreaks.com/topic/264022-simplexmlelement-object-echo-a-value/ Share on other sites More sharing options...
requinix Posted June 12, 2012 Share Posted June 12, 2012 You would do it like I showed in your other thread. Link to comment https://forums.phpfreaks.com/topic/264022-simplexmlelement-object-echo-a-value/#findComment-1353051 Share on other sites More sharing options...
tqla Posted June 12, 2012 Author Share Posted June 12, 2012 Hello requinix. I do this: $xml = simplexml_load_file('test.xml'); print_r($xml); and I get the array in my original post. I add this but it doesn't print a value for $test: $test = (string)$xml->pix[0]->pic; echo $test; Is this what you mean? Thanks. Link to comment https://forums.phpfreaks.com/topic/264022-simplexmlelement-object-echo-a-value/#findComment-1353055 Share on other sites More sharing options...
tqla Posted June 12, 2012 Author Share Posted June 12, 2012 Solved. Was missing 'attributes()'. $test = (string)$xml->pix[0]->attributes()->pic; echo $test; Thanks requinix. Link to comment https://forums.phpfreaks.com/topic/264022-simplexmlelement-object-echo-a-value/#findComment-1353059 Share on other sites More sharing options...
requinix Posted June 12, 2012 Share Posted June 12, 2012 Oops >_> Er, I mean, yeah. I said "like". As in "similar to but not exactly" Link to comment https://forums.phpfreaks.com/topic/264022-simplexmlelement-object-echo-a-value/#findComment-1353061 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.