xrgt Posted February 26, 2007 Share Posted February 26, 2007 How can i strip the following output and access the variables via an array? The buffered output i'm expecting is always in the following format: <html><body> processingError= <br> processingErrorMessage= <br> transactionApproved= <br> responseCode= <br> transactionNo= <br> receiptNo= <br> merchantTXRef= <br> transactionDeclined= <br> creditCardExpired= <br> insufficientFunds= </body></html> This is the payment module code i'm trying to work with: <?php // Get result $vpcResponse = ob_get_contents(); // Finish with the buffer ob_end_clean(); // Check for errors if(strchr($vpcResponse,"<html>")) $errorMessage = $vpcResponse; else if(curl_error($clientURL)) $errorMessage = "CURL ERROR: " . curl_errno($clientURL) . " " . curl_error($clientURL); // Close the connection curl_close($clientURL); $responseKeyVals = split("&", $vpcResponse); foreach ($responseKeyVals as $val) { $param = split("=", $val); $responseArray[urldecode($param[0])] = urldecode($param[1]); } // Process the results and determine the transactions status $transactionResponse = $responseArray['responseCode']; ?> Thanks. Quote Link to comment Share on other sites More sharing options...
xrgt Posted February 27, 2007 Author Share Posted February 27, 2007 anybody? Quote Link to comment Share on other sites More sharing options...
xrgt Posted February 27, 2007 Author Share Posted February 27, 2007 In Java i'd do it this way - PHP i have no idea, can anyone assist?: resp = new BufferedReader(new InputStreamReader(gateway.openStream())); resp.readLine(); String inputLine2=resp.readLine(); resp.readLine(); String inputLine4=resp.readLine(); resp.readLine(); String inputLine6=resp.readLine(); resp.readLine(); String inputLine8=resp.readLine(); //and so on... paymentDetail.setResponseCode(inputLine8.substring(13,inputLine8.length())); paymentDetail.setTransactionNo(inputLine10.substring(14,inputLine10.length())); paymentDetail.setReceiptNo(inputLine12.substring(10,inputLine12.length())); Quote Link to comment Share on other sites More sharing options...
xrgt Posted February 28, 2007 Author Share Posted February 28, 2007 For anyone that is interested, this is what i came up with by modifying the existing code: <?php $content2 = str_replace(array("<html>", "<body>", "<br>"), "", $vpcResponse); $responseKeyVals = split("\r\n", $content2); foreach ($responseKeyVals as $val) { $param = split("=", $val); $responseArray[urldecode($param[0])] = urldecode($param[1]); } ?> <?php echo $responseArray['responseCode']; ?> Quote Link to comment 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.