Jump to content

empty a file created by fsockopen


ruraldev

Recommended Posts

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);

Link to comment
https://forums.phpfreaks.com/topic/268545-empty-a-file-created-by-fsockopen/
Share on other sites

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.