ruraldev Posted September 19, 2012 Share Posted September 19, 2012 I am opening a connection to a server to allow me to send a xml command which returns xml data to me, however when the connection is made I receive data from the server, once I send the xml command the returned xml data is appended to the original data from the server. My question is can I clear the file of the connection data or ignore it totally or over-write it? The code all works, it is just this extra data I want to remove. This is my current code: $xml_data ="<xml string to be sent to server goes here>"; $ras = fsockopen($svr_add,$svr_port,$errno,$errstr,$svr_timeout); fputs ($ras, $xml_data); $ras1 = stream_get_contents($ras, -1, -1); fclose($ras); $xml = $ras1; echo print_r($xml); Quote Link to comment https://forums.phpfreaks.com/topic/268545-empty-a-file-created-by-fsockopen/ Share on other sites More sharing options...
Christian F. Posted September 19, 2012 Share Posted September 19, 2012 If this information is added on the remote server, no. If it's created on the local server, you'll need to show us the code that actually creates the file. Quote Link to comment https://forums.phpfreaks.com/topic/268545-empty-a-file-created-by-fsockopen/#findComment-1379199 Share on other sites More sharing options...
ruraldev Posted September 19, 2012 Author Share Posted September 19, 2012 Unfortunately it comes from the remote server! If I use telnet to connect then I get the connection data as soon as it connects. Quote Link to comment https://forums.phpfreaks.com/topic/268545-empty-a-file-created-by-fsockopen/#findComment-1379200 Share on other sites More sharing options...
Christian F. Posted September 19, 2012 Share Posted September 19, 2012 Ok... If I understand this correctly you're getting the connection string as part of the reply, and you want to remove this string from the data you get. What's stopping you from simply removing it (replacing with '') from the returned data, since you already know exactly what the connection string is? str_replace () should be all you need. Quote Link to comment https://forums.phpfreaks.com/topic/268545-empty-a-file-created-by-fsockopen/#findComment-1379205 Share on other sites More sharing options...
ruraldev Posted September 19, 2012 Author Share Posted September 19, 2012 The connection string is almost exactly the same each time but there is a couple of characters different. eg. ?U?? Quote Link to comment https://forums.phpfreaks.com/topic/268545-empty-a-file-created-by-fsockopen/#findComment-1379210 Share on other sites More sharing options...
Christian F. Posted September 19, 2012 Share Posted September 19, 2012 Is this a change that you control, as in do you send it to the server, or is it generated by the server outside of your control? If the latter, then Regular Expressions or substr () should fix it. If the former, my previous statement is still true. Quote Link to comment https://forums.phpfreaks.com/topic/268545-empty-a-file-created-by-fsockopen/#findComment-1379213 Share on other sites More sharing options...
ruraldev Posted September 19, 2012 Author Share Posted September 19, 2012 It is not something I control, as soon as the connection happens the string is returned. I'll try the fix you suggest later and hopefully that will solve it for me. Thanks for your help Gordon Quote Link to comment https://forums.phpfreaks.com/topic/268545-empty-a-file-created-by-fsockopen/#findComment-1379215 Share on other sites More sharing options...
ruraldev Posted September 19, 2012 Author Share Posted September 19, 2012 Thanks, I used a combination of strpos() and substr() and it works perfectly It's very slow but that'll be a different issue! Regards Gordon Quote Link to comment https://forums.phpfreaks.com/topic/268545-empty-a-file-created-by-fsockopen/#findComment-1379347 Share on other sites More sharing options...
Christian F. Posted September 19, 2012 Share Posted September 19, 2012 You're welcome, glad I could help. Quote Link to comment https://forums.phpfreaks.com/topic/268545-empty-a-file-created-by-fsockopen/#findComment-1379401 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.