'php hacks', 'author' => 'jack herrington', 'publisher' => o'reilly);$books[] = array( 'title' => 'podcasting hacks', 'author' => 'jack herrington', 'publisher' => o'reilly);$doc = new domdocument();$doc->formatoutput = true;$r = $doc->createelement(books);$doc->appendchild($r);foreach ($books as $book) { $b = $doc->createelement(book); $author = $doc->createelement(author); $author->appendchild($doc->createtextnode($book['author'])); $b->appendchild($author); $title = $doc->createelement(title); $title->appendchild($doc->createtextnode($book['title'])); $b->appendchild($title); $publisher = $doc->createelement(publisher); $publisher->appendchild($doc->createtextnode($book['publisher'])); $b->appendchild($publisher); $r->appendchild($b);}echo $doc->savexml();?>
教程链接:
随意转载~但请保留教程地址★