iphone - php can't use SimpleXMLElement(500 server error), and can't echo out data -



iphone - php can't use SimpleXMLElement(500 server error), and can't echo out data -

i have 2 problems. (1) wrote iphone app send updated gps info iphone periodically(maybe period=1s). wrote these lines in server's php

<html> <body> <?php $xmlfile = file_get_contents("php://input"); echo $xmlfile."<br>"; echo "hello world!"; ?> </body> </html>

and in iphone side, implement nsurlconnection delegate method

connection: didreceivedata:

by printing info out in xcode console test whether xml string has been sent server. , receive next in xcode console successfully,

<html><body><openingtagofxml>the xml string sent.</openingtagofxml><br>hello world!</body></html>

but, when running app, visit www.mywebsite.com/index.php(i.e. php shown above), only hello world! shown on page! suppose xml code can displayed out on client browser, too. why? because xmlfile variable changing?

(2)when utilize simplexmlelement, or built-in function simplexml_load_string, 500 internal server error occurs on webpage, like

$xml = new simplexmlelement($xmlfile); echo $xml->asxml();

and also, when tried code below,

$xmlfile = file_get_contents("php://input"); $xfstr = $xmlfile; echo $xfstr."<br>"; $xml = <<<xml $xfstr xml; echo $xml; $doc = new domdocument(); if($doc->loadxml($xml)) { echo "xml loaded! "; } else { echo "xml not loaded! "; if(empty($doc)){ echo "xml empty. "; }else{echo "xml not empty. ";} }

in returned info in xcode console, displayed "xml not loaded!" , "xml not empty"(but, please note can see xml code have sent server on xcode console). don't know why can loaded!

php iphone simplexml echo domdocument

Comments