Jump to content

mobifree

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Everything posted by mobifree

  1. Sorry to bring up an incredibly old thread. I figured since the subject is follow up on the original topic, why waste a new thread. <? include(".inc/config.php"); $xml = file_get_contents("php://input"); $xmlobj = simplexml_load_string($xml); // Play with objects $imei = $xmlobj->imei; $code = $xmlobj->unlockcode; $message = " $xml IMEI: $imei Code: $code "; mailt($to, $subject, $message, "From: $from"); ?> This is the e-mail I get. Where $code and $imei are blank. I'm just e-mailing myself so that I can see what exactly is being outputted. Ideally I just want to have 2 usable variables ($imei and $code) from the xml response from the API server. Help is appreciated. Thanks,
  2. Thanks for the response. Here's my question. Since there is no actual XML file that resides on my server (the xml information is a response from a 3rd party server) how will I handle the information? Will I have to create a script to first write a temp .xml file with the response then, use the SimpleXML script to parse this data into an array? Or is there a 1 shot process where the XML response from the 3rd party server gets parsed in the same script (without creating a temp .xml file everytime the 3rd party server sends a response)? Thanks in advance.
  3. 'm trying to write a script that will covert an XML response to an Array. The format of the xml response is the following (1 of 2 possibilities): if found <response> <imei>123123123123111</imei> <unlockcode>34343434</unlockcode> </response> if not found: <response> <imei>123123123123111</imei> <unlockcode>Not Found</unlockcode> </response> I've been able to create the xml files yes.xml and no.xml and using this script I found on the internet have been able to parse it. <?php function objectsIntoArray($arrObjData, $arrSkipIndices = array()) { $arrData = array(); // if input is object, convert into array if (is_object($arrObjData)) { $arrObjData = get_object_vars($arrObjData); } if (is_array($arrObjData)) { foreach ($arrObjData as $index => $value) { if (is_object($value) || is_array($value)) { $value = objectsIntoArray($value, $arrSkipIndices); // recursive call } if (in_array($index, $arrSkipIndices)) { continue; } $arrData[$index] = $value; } } return $arrData; } $xmlUrl = "no.xml"; // XML feed file/URL $xmlStr = file_get_contents($xmlUrl); $xmlObj = simplexml_load_string($xmlStr); $arrXml = objectsIntoArray($xmlObj); // print_r($arrXml); // print $arrXml['unlockcode']; if ($arrXml['unlockcode'] == "Not Found") { echo "Unable to find the unlock code"; } else { echo "Found the code! Here it is!"; echo $arrXml['unlockcode']; } ?> What I'm trying to do is create a file response.php that will parse the information sent from the server in the xml format described above into an array (instead of reading it from a local file). Your help is appreciated! Thanks in advance.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.