This question already has an answer here:
How could I inlcude the following php code in a xml file or how I change the xml file to a php file? Maybe SimpleXML is a solution, but I don't understand, how to use it.
You can find the live search script for what I need such a XML file here: http://www.w3schools.com/php/php_ajax_livesearch.asp
<?php
foreach ($verbs["a"] as $key => $list) {
echo '<link>'."
";
echo '<title>'.($verbs["a"][$key]).'</title>'."
";
echo '<url>a/'.letter($verbs["a"][$key]).'/</url>'."
";
echo '</link>'."
";
}
?>
</div>
XML files don't process PHP, but PHP can read or output XML files. Look into it in the reverse manner-- including XML within a PHP page. An example of this is SimpleXML (from the php manual online: http://php.net/manual/en/simplexml.examples-basic.php).
You can modify the header for PHP output so that a browser sees it as XML like so:
<?php
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
?>
To elaborate on Jeff Clayton's answer, you'll probably want to look into PHP's support for actually creating XML documents. If your requirements are that you must have a .xml file and you must use PHP to create elements, SimpleXML has functions to meet both requirements:
http://php.net/manual/en/book.simplexml.php
You can instantiate a SimpleXMLElement object by reading what I assume is an existing XML file into a string.
$my_xml_file = file_get_contents('somexml.xml');
You can then use that string to instantiate a SimpleXMLElement:
$xml_for_parsing = new SimpleXMLElement($my_xml_file);
You can then add elements to your XML programmatically via the SimpleXMLElement object's addChild
method.
Finally, you can use SimpleXMLElements asXML
method to save the updated XML as an XML file.
If you require more robust (while arguably more complex) functionality, you might consider looking into PHP's DOM: