selenin Posted October 17, 2012 Share Posted October 17, 2012 Hi I want to check if an user is online, if the user is online the object is set otherwise it doesn't exist. I tried it like that but it doesn't work at all. $cams = new SimpleXMLElement('http://chaturbate.com/affiliates/api/onlinerooms/?format=xml&wm=N6TZA', null, true); if (isset($cams->username['chantal'])){ echo "online"; } Link to comment https://forums.phpfreaks.com/topic/269595-simplexml-problem/ Share on other sites More sharing options...
ignace Posted October 17, 2012 Share Posted October 17, 2012 You need to use XPath $cams = new SimpleXMLElement('http://chaturbate.com/affiliates/api/onlinerooms/?format=xml&wm=N6TZA', null, true); foreach ($cams->xpath('//username') as $username) { echo $username, '<br>', PHP_EOL; } Link to comment https://forums.phpfreaks.com/topic/269595-simplexml-problem/#findComment-1385851 Share on other sites More sharing options...
selenin Posted October 17, 2012 Author Share Posted October 17, 2012 Don't get it just a blank site any other solution Link to comment https://forums.phpfreaks.com/topic/269595-simplexml-problem/#findComment-1385857 Share on other sites More sharing options...
ignace Posted October 17, 2012 Share Posted October 17, 2012 Post your code... As it works just fine here. Link to comment https://forums.phpfreaks.com/topic/269595-simplexml-problem/#findComment-1385859 Share on other sites More sharing options...
selenin Posted October 17, 2012 Author Share Posted October 17, 2012 Don't understand this xpath that's what I wrote $cams = new SimpleXMLElement('http://chaturbate.com/affiliates/api/onlinerooms/?format=xml&wm=N6TZA', null, true); foreach ($cams->xpath('chantal') as $username) { if ($username == ""){ echo "not online"; }else{ echo "online"; } } Link to comment https://forums.phpfreaks.com/topic/269595-simplexml-problem/#findComment-1385860 Share on other sites More sharing options...
Barand Posted October 17, 2012 Share Posted October 17, 2012 Unfortunately it worked for me too. What kind of site has users with names like "fatcock0001"? Link to comment https://forums.phpfreaks.com/topic/269595-simplexml-problem/#findComment-1385862 Share on other sites More sharing options...
selenin Posted October 17, 2012 Author Share Posted October 17, 2012 lol yes it's adult cam site and I have to write an affiliate code Why are you getting it and I don't, I'm really a null Link to comment https://forums.phpfreaks.com/topic/269595-simplexml-problem/#findComment-1385867 Share on other sites More sharing options...
Barand Posted October 17, 2012 Share Posted October 17, 2012 <?php $cams = new SimpleXMLElement('http://chaturbate.com/affiliates/api/onlinerooms/?format=xml&wm=N6TZA', null, true); $online = false; foreach ($cams->xpath('//username') as $username) { if ($username == "chantal"){ echo " $username online<br />"; $online = true; } } if (!$online) echo "Not online"; ?> Link to comment https://forums.phpfreaks.com/topic/269595-simplexml-problem/#findComment-1385873 Share on other sites More sharing options...
selenin Posted October 17, 2012 Author Share Posted October 17, 2012 Thank you but is not working on my server, I think I'll give it up because the answer of the xml file is so terrible slow Link to comment https://forums.phpfreaks.com/topic/269595-simplexml-problem/#findComment-1385877 Share on other sites More sharing options...
ignace Posted October 18, 2012 Share Posted October 18, 2012 During development you obviously work on a cached version.. $xml = new SimpleXMLElement('chat_cache.xml', null, true); You can download the XML through your browser or using cURL: curl http://chaturbate.com/affiliates/api/onlinerooms/?format=xml&wm=N6TZA > chat_cache.xml Link to comment https://forums.phpfreaks.com/topic/269595-simplexml-problem/#findComment-1385926 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.