hanwellchris Posted November 22, 2007 Share Posted November 22, 2007 Hi I have implemented a socket in PHP 5.1 which sends a command to a 3rd Party server. The server responds with some XML data. However the data I receive has had all of the XML tags removed, so that I get all of the data items concatenated together. I have used some socket monitors, and I am, absolutely certain that the correct data is being sent buy the server, it is just not being received properly by PHP. I am using fsockopen ( 127.0.0.1 ) and fgets, but I have also tried fread and it makes no difference. I still only ever get the data part of the XML string without the tags. I have searched the web and not found anything similar. Does any one know what I might be doing wrong?? Al the Best Chis Quote Link to comment https://forums.phpfreaks.com/topic/78408-why-does-my-php-socket-strip-xml-tags/ Share on other sites More sharing options...
Azu Posted November 22, 2007 Share Posted November 22, 2007 What is the exact code that you are using to try to parse the XML? Quote Link to comment https://forums.phpfreaks.com/topic/78408-why-does-my-php-socket-strip-xml-tags/#findComment-396799 Share on other sites More sharing options...
hanwellchris Posted November 22, 2007 Author Share Posted November 22, 2007 I have not got to the point of parsing the xml. There is no xml to parse! It first fell over in my xml parsing, and that has let me back to the reception of the data through the socket. I read from the socket with the following function; function RLogWebServer( $Command, $Parameters ) { $fp = fsockopen( "127.0.0.1", 3400, $errno, $errstr, 10 ); if ( !$fp ) { echo "<br />$errstr ( $errno )<br />\n"; $Result = Array(); } else { // Build the command (and parameter list) string $Out = $Command; if ( $Parameters != '' ) { $Out .= ":".$Parameters; } $Out .= "\n"; fputs( $fp, $Out, strlen( $Out ) ); fflush( $fp ); $In = ''; while ( !feof( $fp ) ) { $In .= fgets( $fp, 128 ); } fclose( $fp ); $Result = explode( "@@", trim($In) ); } return $Result; } I have put print statements at all points in this function and it is clear that the opriginal XML is nopt making it to the fgets function. The $In that I build the result in always contains the data part of the xml string. If I send; <Sensor><Name>Sensor1</Name><Type>7</Type><Status>0</Status></Sensor> down the socket, I receive; Sensor170 This is madness!!. I can see using socket tools (tcpspy) that I really am sending the full XML type string into the socket, but it just doesn't seem to be coming out the other end. It is as if some kind of filter is acting on the stream that I am not aware of. This same code worked 18months ago when I first tried it. I have just resurrected it for another project, and got stumped at the first hurdle. It seems as if it must be some PHP.INI setting, but I don't know what. All the Best Chris Quote Link to comment https://forums.phpfreaks.com/topic/78408-why-does-my-php-socket-strip-xml-tags/#findComment-396803 Share on other sites More sharing options...
PattyMatheson Posted September 12, 2009 Share Posted September 12, 2009 I hope you've found the solution after all But if anyone encounters such problem in the future... When you display your POST data try to use this function: htmlspecialchars() htmlspecialchars($_POST['data']) Because the data is being sent properly, only when you display it, the php server ignores any tags in strings. This function changes "<" and some others into entities. Sending: $data = '<?xml version="1.0" encoding="UTF-8"?>'; $data .= '<test>'; $data .= '<gość>'; $data .= '<imię>Antek</imię>'; $data .= '<nazwisko>Jóźwiak</nazwisko>'; $data .= '<adres>Polna 12/4</adres>'; $data .= '<telefon>505444888</telefon>'; $data .= '</gość>'; $data .= '</test>'; You get <?xml version=\"1.0\" encoding=\"UTF-8\"?><test><gość><imię>Antek</imię><nazwisko>Jóźwiak</nazwisko><adres>Polna 12/4</adres><telefon>505444888</telefon></gość></test> Hope this would help. Quote Link to comment https://forums.phpfreaks.com/topic/78408-why-does-my-php-socket-strip-xml-tags/#findComment-917225 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.