如何将div的内容写入文件的开头[重复]

This question already has an answer here:

I have the function xy that writes php to the document:

go.php

<?php
$file_data = '?';
$file_data .= file_get_contents('xml.xml');
file_put_contents('xml.xml', $file_data);
?>
")}

HTML

   <div id="content"contenteditable>
  <contenttag>hello</contenttag>
  <logo>hi</logo>
  </div>

I would like the content of the #content to be written to the start of XML.xml

Note: I could not find a clear answer on Google

</div>

The two best options for dealing with XML data are SimpleXML and DOMDocument. In either case you can use an xpath query to target particular elements. Eg:

$doc = new DOMDocument;
$doc->load("xml.xml");
$xpath = new DOMXPath($doc);
$query = "*/div[@id='content']"\;
$elements = $xpath->query($query);

foreach($elements as $el) {
    // $el->nodeValue 
}