【发布时间】:2016-03-31 15:45:53
【问题描述】:
<?php
if (isset($_POST['insert'])) {
$xml = new DomDocument("1.0","UTF-8");
$xml->load('rss.xml');
$title = $_POST['title'];
$image = $_POST['image'];
$user = $_POST['user'];
$date = date("Y/m/d");
$indent = $_POST['indent'];
$description = $_POST['description'];
$rootTag = $xml->documentElement;
$entryTag = $xml->createElement("entry");
$titleTag = $xml->createElement("title", $title);
$imageTag = $xml->createElement("image", $image);
$userTag = $xml->createElement("user", $user);
$dateTag = $xml->createElement("date", $date);
$indentTag = $xml->createElement("indent", $indent);
$descriptionTag = $xml->createElement("description", $description);
$entryTag->appendChild($titleTag);
$entryTag->appendChild($imageTag);
$entryTag->appendChild($userTag);
$entryTag->appendChild($dateTag);
$entryTag->appendChild($indentTag);
$entryTag->appendChild($descriptionTag);
$rootTag->appendChild($entryTag);
$xml->save('rss.xml');
}
?>
我想在其他元素之前插入这个,我可以帮忙,这个编码工作
这是我想要的:
旧的xml
<channel>
<entry>
<title>We Are Back</title>
<image>assets/img/landscape-mountains-nature-clouds.jpg</image>
<user>RKGaming Admin</user>
<date>1/14/16</date>
<indent>It's</indent>
<description>
our first post in the year 2016, sorry the website has been down we have been working on it trying to integrate a login system for the consumer base. We thank you for your time to wait and hope you enjoy the new updates coming from our company RKGaming in the near future. We still are looking for people to work with, so please join our ranks and sign up for the company so we can produce the game!
</description>
</entry>
</channel>
表单提交后的新 XML
<channel>
<entry>
<title>test</title>
<image>test</image>
<user>test</user>
<date>2016/03/31</date>
<indent>test</indent>
<description>test</description>
</entry>
<entry>
<title>We Are Back</title>
<image>assets/img/landscape-mountains-nature-clouds.jpg</image>
<user>RKGaming Admin</user>
<date>1/14/16</date>
<indent>It's</indent>
<description>
our first post in the year 2016, sorry the website has been down we have been working on it trying to integrate a login system for the consumer base. We thank you for your time to wait and hope you enjoy the new updates coming from our company RKGaming in the near future. We still are looking for people to work with, so please join our ranks and sign up for the company so we can produce the game!
</description>
</entry>
</channel>
如果你能帮我编写这个代码真的需要它,所以它不会以错误的方式打印出提要
【问题讨论】:
-
如果你把
echo gettype($xml);die();放在第13行,它输出object吗? -
是的,它剂量输出对象
-
这可能很有用,stackoverflow.com/a/30582620