ruraldev Posted June 16, 2012 Share Posted June 16, 2012 Can anyone help me print the output from fsockopen, I create a variable called $var It returns an xml format <tag> <element1>one</element1> <element2>two</element2> <element3>three</element3> </tag> I can output the values onetwothree using fputs and fgets but I need to be able to display just a single element, I am sure this is simple but I still can't work it out. Hope someone can help. Thanks Gordon Quote Link to comment https://forums.phpfreaks.com/topic/264294-read-fsockopen-result/ Share on other sites More sharing options...
xyph Posted June 16, 2012 Share Posted June 16, 2012 SimpleXML is probably your best bet. Quote Link to comment https://forums.phpfreaks.com/topic/264294-read-fsockopen-result/#findComment-1354414 Share on other sites More sharing options...
ruraldev Posted June 16, 2012 Author Share Posted June 16, 2012 I tried simplexml_load_string and simplexml_load_file but neither worked. Should I be using something else? Gordon Quote Link to comment https://forums.phpfreaks.com/topic/264294-read-fsockopen-result/#findComment-1354417 Share on other sites More sharing options...
xyph Posted June 16, 2012 Share Posted June 16, 2012 'Neither worked' is a horrible error report. I can't help you without more details. I assure you, SimpleXML is probably the ideal solution to this, unless you don't mind manually parsing with RegEx Quote Link to comment https://forums.phpfreaks.com/topic/264294-read-fsockopen-result/#findComment-1354418 Share on other sites More sharing options...
ruraldev Posted June 16, 2012 Author Share Posted June 16, 2012 Sorry, error is: Warning: simplexml_load_string() expects parameter 1 to be string Same with load_file I see that fsockopen outputs a file pointer but how do i get the info from it? Quote Link to comment https://forums.phpfreaks.com/topic/264294-read-fsockopen-result/#findComment-1354422 Share on other sites More sharing options...
xyph Posted June 16, 2012 Share Posted June 16, 2012 Use fgets, like you did to display it. Quote Link to comment https://forums.phpfreaks.com/topic/264294-read-fsockopen-result/#findComment-1354423 Share on other sites More sharing options...
ruraldev Posted June 16, 2012 Author Share Posted June 16, 2012 I couldn't find a way to select the different elements using fgets, is it possible? Quote Link to comment https://forums.phpfreaks.com/topic/264294-read-fsockopen-result/#findComment-1354424 Share on other sites More sharing options...
boompa Posted June 16, 2012 Share Posted June 16, 2012 Is it really so hard to just post the code that's not working, rather than this useless "back and forth"? It's probably fixed in one post if you provide that. Quote Link to comment https://forums.phpfreaks.com/topic/264294-read-fsockopen-result/#findComment-1354426 Share on other sites More sharing options...
xyph Posted June 16, 2012 Share Posted June 16, 2012 I couldn't find a way to select the different elements using fgets, is it possible? Use the results from fgets to generate your SimpleXML instance. This might be beyond your current PHP abilities. Quote Link to comment https://forums.phpfreaks.com/topic/264294-read-fsockopen-result/#findComment-1354427 Share on other sites More sharing options...
ruraldev Posted June 16, 2012 Author Share Posted June 16, 2012 Code is below, however it wouldn't work live as the remote machine is behind a firewall and only certain IP's are allowed through. It does get a response as I can see it but it is just a single long string. You may well be correct that this is beyond my abilities! $var = fsockopen($svr_add,$svr_port,$errno,$errstr,$svr_timeout); if(!$var) { echo "Connextion Failed\n"; exit(); } else { fputs ($var, $xml_data); echo fgets ($var, 128); fclose($var); } Quote Link to comment https://forums.phpfreaks.com/topic/264294-read-fsockopen-result/#findComment-1354430 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.