这篇文章介绍的内容是关于php 生成XML ,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
$doc = new DOMDocument('1.0', 'utf-8'); // 声明版本和编码 $doc->formatOutput = true; $r = $doc->createElement("root"); $doc->appendChild($r); $arr = array( array( 'name' => 'zhangsan', 'sex' => 'male', 'age' => 20, ), array( 'name' => 'lisi', 'sex' => 'female', 'age' => 25, ), ); foreach ($arr as $dat) { $b = $doc->createElement("data"); $name = $doc->createElement("name"); $name->appendChild($doc->createTextNode($dat['name'])); $b->appendChild($name); $sex = $doc->createElement("sex"); $sex->appendChild($doc->createTextNode($dat['sex'])); $b->appendChild($sex); $age = $doc->createElement("age"); $age->appendChild($doc->createTextNode($dat['age'])); $b->appendChild($age); $r->appendChild($b); }
登录后复制
相关推荐:
以上就是php 生成XML的详细内容,更多请关注Work网其它相关文章!