NickAlbert Posted June 27, 2013 Share Posted June 27, 2013 I need to get the values from an XML result from a URL. Here is what I have tried to work out after reading tutorials, but am stumped as to going further: <? $xmlstr = file_get_contents("https://www.site.com/checksession.asp?clientid=3915&password=byuc0913&wait=60&sessionid=8863AC8A23498DDC27993EF9F6330C50B2B4FDFE"); $reply = new SimpleXMLElement($xmlstr); $reponse = ""; $completed = ""; $last4 = ""; $approvedamt = ""; ?> Here is the output of the URL in file_get_contents: <?xml version="1.0" encoding="utf-8"?> <reply> <response>Success</response> <responsecode>0</responsecode> <description>OK</description> <responseurl>/soft/checksession.asp</responseurl> <datablock> <sessionid>8863AC8A23498DDC27993EF9F6330C50B2B4FDFE</sessionid> <completed>yes</completed> <approved>Y</approved> <declinecount>0</declinecount> <gateid>76479220</gateid> <transtype>SALE</transtype> <authcode>191330</authcode> <avsreply>U</avsreply> <cvv2reply> </cvv2reply> <declinestr>OK</declinestr> <cardtype>V</cardtype> <cardname>Visa</cardname> <first6>403491</first6> <last4>4971</last4> <keyed>No</keyed> <expmonth>07</expmonth> <expyear>16</expyear> <approvedamt>9.67</approvedamt> <tip>0</tip> <bal></bal> <invoiceno>22513</invoiceno> <corporatecardindicator></corporatecardindicator> <processor_token></processor_token> </datablock> </reply> Any help would be GREATLY appreciated! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/279640-working-with-xml-results-from-a-url/ Share on other sites More sharing options...
AbraCadaver Posted June 27, 2013 Share Posted June 27, 2013 The examples should show you how to access these. Plus, do a print_r($reply) to see the nesting, which is the same as the XML. Try: echo $reply->response; echo $reply->datablock->completed; Quote Link to comment https://forums.phpfreaks.com/topic/279640-working-with-xml-results-from-a-url/#findComment-1438265 Share on other sites More sharing options...
NickAlbert Posted June 27, 2013 Author Share Posted June 27, 2013 <? $xmlstr = file_get_contents("https://www.site.com/checksession.asp?clientid=3915&password=byuc0913&wait=60&sessionid=8863AC8A23498DDC27993EF9F6330C50B2B4FDFE"); $reply = new SimpleXMLElement($xmlstr); echo $reply->response; echo $reply->datablock->completed; ?> Gave this as output: Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 34: parser error : Opening and ending tag mismatch: meta line 15 and head in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: </head> in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 37: parser error : Entity 'nbsp' not defined in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: </div> in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 117: parser error : Entity 'nbsp' not defined in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: </div> in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 141: parser error : Opening and ending tag mismatch: br line 140 and div in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: </div> </div> in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 141: parser error : Opening and ending tag mismatch: br line 140 and div in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: </div> </div> in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 195: parser error : Opening and ending tag mismatch: div line 120 and body in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: </body> in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 196: parser error : Opening and ending tag mismatch: div line 119 and html in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: </html> in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 197: parser error : Premature end of data in tag body line 35 in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 197: parser error : Premature end of data in tag head line 3 in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 197: parser error : Premature end of data in tag html line 2 in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/tdh/public_html/network/esid/SCD_checksession.php:5 Stack trace: #0 /home/tdh/public_html/network/esid/SCD_checksession.php(5): SimpleXMLElement->__construct('??<!DOCTYPE htm...') #1 {main} thrown in /home/tdh/public_html/network/esid/SCD_checksession.php on line 5 Quote Link to comment https://forums.phpfreaks.com/topic/279640-working-with-xml-results-from-a-url/#findComment-1438287 Share on other sites More sharing options...
NickAlbert Posted June 28, 2013 Author Share Posted June 28, 2013 Anybody? Quote Link to comment https://forums.phpfreaks.com/topic/279640-working-with-xml-results-from-a-url/#findComment-1438382 Share on other sites More sharing options...
boompa Posted June 28, 2013 Share Posted June 28, 2013 Bad XML. In fact, given the presence of head and div tags, I'd say you're getting back HTML. Maybe your login has expired? Quote Link to comment https://forums.phpfreaks.com/topic/279640-working-with-xml-results-from-a-url/#findComment-1438384 Share on other sites More sharing options...
NickAlbert Posted June 28, 2013 Author Share Posted June 28, 2013 Thanks boompa, had a character off in the session string! Ok now when I run the script it outputs: Successyes How do I have the script just pull the "approved" data and the "last4" data as a string to work with? Quote Link to comment https://forums.phpfreaks.com/topic/279640-working-with-xml-results-from-a-url/#findComment-1438394 Share on other sites More sharing options...
Solution boompa Posted June 28, 2013 Solution Share Posted June 28, 2013 Refer to AbraCadaver's response #2 and change the field names accordingly. Quote Link to comment https://forums.phpfreaks.com/topic/279640-working-with-xml-results-from-a-url/#findComment-1438403 Share on other sites More sharing options...
NickAlbert Posted June 28, 2013 Author Share Posted June 28, 2013 Got it! Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/279640-working-with-xml-results-from-a-url/#findComment-1438405 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.