Noonga Posted November 22, 2011 Share Posted November 22, 2011 I send off this: <?php $data = "<egateway> <eCardExpiryMonth>01</eCardExpiryMonth> <eCardExpiryYear>04</eCardExpiryYear> <eCardHoldersName>Joe Bloke</eCardHoldersName> <eCardNumber>4444333322221111</eCardNumber> <eCVN>123</eCVN> <eTotalAmount>100</eTotalAmount> </egateway> "; $ch = curl_init(); curl_setopt($ch, CURLOPT_POSTFIELDS, $edata); curl_setopt($ch, CURLOPT_URL, "https://www.example.com/gateway_cvn/testpage.asp"); curl_exec($ch); curl_close($ch); ?> In return, I get the following XML: <eResponse> <eTrxnStatus>True</eTrxnStatus> <eTrxnNumber>20219</eTrxnNumber> <eAuthCode>123456</eAuthCode> <eReturnAmount>100</eReturnAmount> <eTrxnError>00,Transaction Approved(Test CVN Gateway)</eTrxnError> </eResponse> Is there a way to make it so this does not show, and instead I can make PHP do something like: if (eTrxnStatus == True) {// do stuff}; ? Quote Link to comment https://forums.phpfreaks.com/topic/251596-php-performing-on-xml-response/ Share on other sites More sharing options...
joel24 Posted November 22, 2011 Share Posted November 22, 2011 use simpleXML... have a look at the examples Quote Link to comment https://forums.phpfreaks.com/topic/251596-php-performing-on-xml-response/#findComment-1290322 Share on other sites More sharing options...
silkfire Posted November 22, 2011 Share Posted November 22, 2011 Would be easy with SimpleXML: $data = '<egateway> <eCardExpiryMonth>01</eCardExpiryMonth> <eCardExpiryYear>04</eCardExpiryYear> <eCardHoldersName>Joe Bloke</eCardHoldersName> <eCardNumber>4444333322221111</eCardNumber> <eCVN>123</eCVN> <eTotalAmount>100</eTotalAmount> </egateway>'; $ch = curl_init(); curl_setopt($ch, CURLOPT_POSTFIELDS, $edata); curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/gateway_cvn/testpage.asp'); $xml = simplexml_load_string(curl_exec($ch)); if ($xml->eTrxnStatus == 'True') echo 'It\'s true!'; else echo 'It\'s false!'; Quote Link to comment https://forums.phpfreaks.com/topic/251596-php-performing-on-xml-response/#findComment-1290325 Share on other sites More sharing options...
Noonga Posted November 22, 2011 Author Share Posted November 22, 2011 Joel, That wouldn't help because I would not be able to set variables on the page being sent to me. Thanks anyway though. silkfire. Thanks for that mate. I'll start reading into that string now to see how it works exactly. Do you know how I can hide the response XML? Quote Link to comment https://forums.phpfreaks.com/topic/251596-php-performing-on-xml-response/#findComment-1290326 Share on other sites More sharing options...
Noonga Posted November 22, 2011 Author Share Posted November 22, 2011 I tried this, but am getting the same result as before. Have I mucked up? $data = '<egateway> <eCardExpiryMonth>01</eCardExpiryMonth> <eCardExpiryYear>04</eCardExpiryYear> <eCardHoldersName>Joe Bloke</eCardHoldersName> <eCardNumber>4444333322221111</eCardNumber> <eCVN>123</eCVN> <eTotalAmount>100</eTotalAmount> </egateway>'; $ch = curl_init(); curl_setopt($ch, CURLOPT_POSTFIELDS, $edata); curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/gateway_cvn/testpage.asp'); $response = simplexml_load_string(curl_exec($ch)); if ($response -> eTrxnStatus == 'True') { echo "True 1111111111111."; } curl_exec($ch); curl_close($ch); ?> Quote Link to comment https://forums.phpfreaks.com/topic/251596-php-performing-on-xml-response/#findComment-1290332 Share on other sites More sharing options...
silkfire Posted November 22, 2011 Share Posted November 22, 2011 Why are you executing the CURL again at the end? curl_exec($ch); curl_close($ch); curl_close is not necessary. Is the echo not working? any errors you get? Quote Link to comment https://forums.phpfreaks.com/topic/251596-php-performing-on-xml-response/#findComment-1290335 Share on other sites More sharing options...
Noonga Posted November 22, 2011 Author Share Posted November 22, 2011 Yeah, I noticed the double execution myself and removed it. I close $ch with curl_close() because that is how curl_close() is used in the PHP manual. Correct, the echo is not working. all I see is the output response (the XML). I am getting these issues in my error log: PHP Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found simplexml_load_string(): 1 simplexml_load_string(): ^ PHP Notice: Trying to get property of non-object Quote Link to comment https://forums.phpfreaks.com/topic/251596-php-performing-on-xml-response/#findComment-1290336 Share on other sites More sharing options...
silkfire Posted November 22, 2011 Share Posted November 22, 2011 It means that your XML response is malformed. Quote Link to comment https://forums.phpfreaks.com/topic/251596-php-performing-on-xml-response/#findComment-1290345 Share on other sites More sharing options...
Noonga Posted November 22, 2011 Author Share Posted November 22, 2011 Oh Dear. Thats what I thought aswell! This is the response I get: <eResponse><eTrxnStatus>True</eTrxnStatus><eTrxnNumber>11673</eTrxnNumber><eTrxnReference/><eReturnAmount>100</eReturnAmount><eTrxnError>00,Transaction Approved(Test CVN Gateway)</eTrxnError></eResponse> What could be wrong with it? Quote Link to comment https://forums.phpfreaks.com/topic/251596-php-performing-on-xml-response/#findComment-1290352 Share on other sites More sharing options...
Noonga Posted November 22, 2011 Author Share Posted November 22, 2011 I solved the problem with: curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); Quote Link to comment https://forums.phpfreaks.com/topic/251596-php-performing-on-xml-response/#findComment-1290368 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.