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"; } Quote 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; } Quote 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 (edited) Don't get it just a blank site any other solution Edited October 17, 2012 by selenin Quote 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 (edited) Post your code... As it works just fine here. Edited October 17, 2012 by ignace Quote 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"; } } Quote 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"? Quote 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 Quote 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 (edited) <?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"; ?> Edited October 17, 2012 by Barand Quote 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 Quote 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 (edited) 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 Edited October 18, 2012 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/269595-simplexml-problem/#findComment-1385926 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.