0

I'm having problem with a php script that is stock data to xml file , and it's just simply not being executed. I get the same code i wrote it in the the output page (in the browser). I am quite sure this is a PHP setting problem because before I have changed the host server it was working fine. That is the codes :

 <?php

 $tag = $price ='ds';

 if ($_SERVER["REQUEST_METHOD"] == "POST") {
 $tag = test_input($_POST["comdtyprice"]);
 $price = test_input($_POST["comdtyprice"]);

 }
 $xml = simplexml_load_file("b.xml");

 $child = $xml->prices[0]->addChild($tag);

 $child->addAttribute("text",$price);
 $xml->asXML("b.xml");

 function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
 }
 ?>

and the output: picture from the browser the browser act with the codes as a string

jonsoft
  • 9
  • 4

1 Answers1

0

I'm wondering if the XML is somehow being interpreted as PHP. Perhaps an XML ?> is encountered, which drops the interpreter out of PHP parsing. This might explain why only part of the code is being echoed out.

Mark Priddy
  • 626
  • 10
  • 19
  • thanks br .please how to fix it – jonsoft Apr 14 '16 at 12:25
  • What do you get from `echo "
    " . print_r($xml, true) . "
    "` after loading the file?
    – Mark Priddy Apr 14 '16 at 16:06
  • Thanks for your attention Mark ?it is the same result .but this time the output was start from :" . print_r($xml, true) . "".......................... – jonsoft Apr 14 '16 at 19:44
  • it looks like ,the interpreter close the secript from the first ">" it find .and all the rest after this ">" will output to the secreen as a string .I am depressed brother – jonsoft Apr 14 '16 at 19:50
  • Do you have access to the PHP error_log for your server? Perhaps some clues might show up there. Right now, I'm simply trying to suggest some troubleshooting. Is the `b.xml` file well formed? – Mark Priddy Apr 14 '16 at 20:16
  • yes b.xml looking good – jonsoft Apr 14 '16 at 20:51