Kristoff1875 Posted May 21, 2012 Share Posted May 21, 2012 I'm getting data from a remote XML file using the following as a result of a form: <?php header('Content-type: text/xml'); //extract data from the post extract($_POST); //set POST variables $url = 'https://www.*******'; $fields = array( 'ESERIES_FORM_ID'=>urlencode($ESERIES_FORM_ID), 'MXIN_USERNAME'=>urlencode($MXIN_USERNAME), 'MXIN_PASSWORD'=>urlencode($MXIN_PASSWORD), 'MXIN_VRM'=>urlencode($MXIN_VRM), 'MXIN_TRANSACTIONTYPE'=>urlencode($MXIN_TRANSACTIONTYPE), 'MXIN_PAYMENTCOLLECTIONTYPE'=>urlencode($MXIN_PAYMENTCOLLECTIONTYPE), 'MXIN_CAPCODE'=>urlencode($MXIN_CAPCODE) ); //url-ify the data for the POST foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); //execute post $result = curl_exec($ch); //close connection curl_close($ch); ?> Which is displaying what was the remote XML page, but has brought it to my domain. How would I go about taking the results of the displaying XML page and displaying them on the next page rather than just displaying the XML data? Many thanks in advanced! Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/ Share on other sites More sharing options...
Kristoff1875 Posted May 21, 2012 Author Share Posted May 21, 2012 <GEODS exp_cid="41C2"><REQUEST type="RETURN" subtype="CALLBUR" EXP_ExperianRef="" success="Y" timestamp="Mon, 21 May 2012 at 12:04 PM" id="41C2"><MB01 seq="01"><DATEOFTRANSACTION>20000628</DATEOFTRANSACTION><VRM>W******</VRM><VINCONFIRMATIONFLAG>0</VINCONFIRMATIONFLAG><ENGINECAPACITY>01989</ENGINECAPACITY><DOORPLAN>14</DOORPLAN><DATEFIRSTREGISTERED>20000531</DATEFIRSTREGISTERED><YEAROFMANUFACTURE>2000</YEAROFMANUFACTURE><SCRAPPED>0</SCRAPPED><EXPORTED>0</EXPORTED><IMPORTED>0</IMPORTED><MAKE>FORD</MAKE><MODEL>FOCUS GHIA</MODEL><COLOUR>BLACK</COLOUR><TRANSMISSION>MANUAL 5 GEARS</TRANSMISSION><ENGINENUMBER>XU20092</ENGINENUMBER><VINSERIALNUMBER>WF0AXXGCDAXU20092</VINSERIALNUMBER><DOORPLANLITERAL>5 DOOR HATCHBACK</DOORPLANLITERAL><MVRISMAKECODE>M1</MVRISMAKECODE><MVRISMODELCODE>AJZ</MVRISMODELCODE><DTPMAKECODE>M1</DTPMAKECODE><DTPMODELCODE>868</DTPMODELCODE><TRANSMISSIONCODE>M</TRANSMISSIONCODE><GEARS>5</GEARS><FUEL>PETROL</FUEL><CO2EMISSIONS>*</CO2EMISSIONS><USEDBEFORE1STREG>0</USEDBEFORE1STREG><IMPORTNONEU>0</IMPORTNONEU><UKDATEFIRSTREGISTERED>20000531</UKDATEFIRSTREGISTERED><MAKEMODEL>FORD FOCUS GHIA</MAKEMODEL></MB01><MB12 seq="01"><CAPCODE>FOFO20GH 5HPIM 1</CAPCODE></MB12></REQUEST></GEODS> Here is the XML result Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347251 Share on other sites More sharing options...
Barand Posted May 21, 2012 Share Posted May 21, 2012 If you save the xml to file <?php $xml = simplexml_load_file("uat.xml"); $data = (array)$xml->REQUEST->MB01; array_shift($data); // remove @attributes echo "<table>\n" ; foreach ($data as $k => $v) { echo "<tr><td>$k</td><td>$v</td></tr>\n"; } echo "</table>\n"; ?> Or you can use simplexml_load_string ($xmlstring). Make sure file or string have the xml header line Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347256 Share on other sites More sharing options...
Kristoff1875 Posted May 21, 2012 Author Share Posted May 21, 2012 Thanks again for this, but i'm not quite sure where I should put it? Should it go under the code I posted above which is the formaction.php page that displays the XML result? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347259 Share on other sites More sharing options...
Barand Posted May 21, 2012 Share Posted May 21, 2012 As that code will display your xml results, you would put it where you want those results to be displayed Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347261 Share on other sites More sharing options...
Kristoff1875 Posted May 21, 2012 Author Share Posted May 21, 2012 I'm currently not sure how to get off the XML page that displays after completing the form. Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347264 Share on other sites More sharing options...
Barand Posted May 21, 2012 Share Posted May 21, 2012 can you attach a "view source" file of the page displayed after the curl call Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347268 Share on other sites More sharing options...
Kristoff1875 Posted May 21, 2012 Author Share Posted May 21, 2012 formaction.php file: <?php header('Content-type: text/xml'); //extract data from the post extract($_POST); //set POST variables $url = 'https://www.***.com/UAT/'; $fields = array( 'ESERIES_FORM_ID'=>urlencode($ESERIES_FORM_ID), 'MXIN_USERNAME'=>urlencode($MXIN_USERNAME), 'MXIN_PASSWORD'=>urlencode($MXIN_PASSWORD), 'MXIN_VRM'=>urlencode($MXIN_VRM), 'MXIN_TRANSACTIONTYPE'=>urlencode($MXIN_TRANSACTIONTYPE), 'MXIN_PAYMENTCOLLECTIONTYPE'=>urlencode($MXIN_PAYMENTCOLLECTIONTYPE), 'MXIN_CAPCODE'=>urlencode($MXIN_CAPCODE) ); //url-ify the data for the POST foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); //execute post $result = curl_exec($ch); //close connection curl_close($ch); ?> Source of formaction.php: <?xml version='1.0' standalone='yes'?><GEODS exp_cid='809i'><REQUEST type='RETURN' subtype='CALLBUR' EXP_ExperianRef='' success='Y' timestamp='Mon, 21 May 2012 at 1:48 PM' id='809i'><MB01 seq='01'><DATEOFTRANSACTION>20020725</DATEOFTRANSACTION><VRM>WF02LPZ </VRM><VINCONFIRMATIONFLAG>0</VINCONFIRMATIONFLAG><ENGINECAPACITY>01199</ENGINECAPACITY><DOORPLAN>13</DOORPLAN><DATEFIRSTREGISTERED>20020625</DATEFIRSTREGISTERED><YEAROFMANUFACTURE>2002</YEAROFMANUFACTURE><SCRAPPED>0</SCRAPPED><EXPORTED>0</EXPORTED><IMPORTED>0</IMPORTED><MAKE>VAUXHALL</MAKE><MODEL>CORSA COMFORT 16V SEMI-AU</MODEL><COLOUR>RED</COLOUR><TRANSMISSION>MANUAL 5 GEARS</TRANSMISSION><ENGINENUMBER>19W84037</ENGINENUMBER><VINSERIALNUMBER>W0L0XCF0824252589</VINSERIALNUMBER><DOORPLANLITERAL>3 DOOR HATCHBACK</DOORPLANLITERAL><MVRISMAKECODE>D8</MVRISMAKECODE><MVRISMODELCODE>AHA</MVRISMODELCODE><DTPMAKECODE>DB</DTPMAKECODE><DTPMODELCODE>858</DTPMODELCODE><TRANSMISSIONCODE>M</TRANSMISSIONCODE><GEARS>5</GEARS><FUEL>PETROL</FUEL><CO2EMISSIONS>149</CO2EMISSIONS><USEDBEFORE1STREG>0</USEDBEFORE1STREG><IMPORTNONEU>0</IMPORTNONEU><UKDATEFIRSTREGISTERED>20020625</UKDATEFIRSTREGISTERED><MAKEMODEL>VAUXHALL CORSA COMFORT 16V SEMI-AU</MAKEMODEL></MB01><MB12 seq='01'><CAPCODE>VACO12C1E3HPIA 1</CAPCODE></MB12></REQUEST></GEODS> Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347269 Share on other sites More sharing options...
Barand Posted May 21, 2012 Share Posted May 21, 2012 As I hoped. Turn on output-buffering and store the output. Use that in my code Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347271 Share on other sites More sharing options...
Kristoff1875 Posted May 21, 2012 Author Share Posted May 21, 2012 I have no idea what how to do it! I'll give it a go now and report back! Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347277 Share on other sites More sharing options...
Kristoff1875 Posted May 21, 2012 Author Share Posted May 21, 2012 I've placed ob_start(); Infront of some of the code, but I just seem to get errors thrown out. Do I need to assign it to a certain function? Sorry, i've not come across this function before! Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347279 Share on other sites More sharing options...
Barand Posted May 21, 2012 Share Posted May 21, 2012 You're on your own with this as no-one else can replicate what you are doing, but At beginning of script put ob_start(); and right at the end of the script try $str = ob_get_contents(); ob_end_clean(); //my code goes here Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347305 Share on other sites More sharing options...
Kristoff1875 Posted May 21, 2012 Author Share Posted May 21, 2012 I was getting errors when adding extra code, assuming it was because of the header being set as xml: header('Content-type: text/xml'); So after taking that out and adding your code at the end, i've now got the following error: Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "uat.xml" in formaction.php on line 48 Is that because it's not saving imported result correctly? Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347308 Share on other sites More sharing options...
Barand Posted May 21, 2012 Share Posted May 21, 2012 Thecode I last posted is using $str to store the output, so you need to use $xml = simplexml_load_str($str); ... instead of the load_file version Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347323 Share on other sites More sharing options...
Kristoff1875 Posted May 21, 2012 Author Share Posted May 21, 2012 That returns: Fatal error: Call to undefined function simplexml_load_str() in /home/gdesignz/public_html/Samples/JACK/formaction.php on line 46 Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347326 Share on other sites More sharing options...
Barand Posted May 21, 2012 Share Posted May 21, 2012 Sorry!! SHould be simplexml_load_string Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347327 Share on other sites More sharing options...
Kristoff1875 Posted May 21, 2012 Author Share Posted May 21, 2012 You're a genius!!! I love you xxxxxxxxxx Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347328 Share on other sites More sharing options...
Kristoff1875 Posted May 21, 2012 Author Share Posted May 21, 2012 Next question for you now (sorry!!!!) is there a way of taking those values and only showing a selection of them rather than all of them and how would I go about just storing the values and passing them to the next page? Is it a case of sending it via the url or can I hide them by sending them as hidden form fields? Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347331 Share on other sites More sharing options...
Barand Posted May 21, 2012 Share Posted May 21, 2012 You can be selective $xml = simplexml_load_string($str); $make = $xml->REQUEST->MB01->MAKE; $model = $xml->REQUEST->MB01->MODEL; echo "$make $model"; // --> JEEP GRAND CHEROKEE LIMITED You have options regarding the next page Hidden fields session vars save xml to file Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347344 Share on other sites More sharing options...
Kristoff1875 Posted May 21, 2012 Author Share Posted May 21, 2012 That's not displaying anything, just a blank page. Quote Link to comment https://forums.phpfreaks.com/topic/262860-getting-data-from-curl-imported-xml-page/#findComment-1347348 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.