注:xml是一个对文法要求非常严格的语言,所以header()和第一句echo "";必须严格按照这样输">
时间:2021-07-01 10:21:17 帮助过:13人阅读
$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生成唯一RequestID类
以上就是php 生成XML的详细内容,更多请关注Gxl网其它相关文章!