星期一, 12月 14, 2009

PHP XML Receive


<?xml version="1.0" encoding="UTF-8"?>
<inventory>
<book>
<author>Nick Chase</author>
<title>XML Primer Plus</title>
<publisher>Sams</publisher>
</book>
<book>
<author>Earth</author>
<title>David Brin</title>
<publisher>Spectra</publisher>
</book>
<movie>
<director>Steven Spielberg</director>
<title>Raiders of the Lost Ark</title>
<actor>Harrison Ford</actor>
<actor>Karen Allen</actor>
</movie>
<movie>
<director>Rob Reiner</director>
<title>The American President</title>
<actor>Michael Douglas</actor>
<actor>Annette Bening</actor>
<actor>Martin Sheen</actor>
</movie>
</inventory>


if (!isset($HTTP_RAW_POST_DATA))
$HTTP_RAW_POST_DATA = file_get_contents("php://input");

header("Content-type: text/plain");
echo $HTTP_RAW_POST_DATA;
?>



if (!isset($HTTP_RAW_POST_DATA))
$HTTP_RAW_POST_DATA = file_get_contents("php://input");

$doc = new DOMDocument();
$doc->loadXML($HTTP_RAW_POST_DATA);

$allBooks = $doc->getElementsByTagName('book');
$numBooks = $allBooks->length;

$allMovies = $doc->getElementsByTagName('movie');
$numMovies = $allMovies->length;

echo "There are ".$numBooks." books and ".$numMovies." movies.";
?>

沒有留言:

張貼留言

留個話吧:)

其他你感興趣的文章

Related Posts with Thumbnails