As mentioned in comments, you are trying to create invalid XML and therefore the SimpleXML extension is of little use here. You need to use normal string manipulation. Here is a fragile (because it is matching on ?>
) implementation:
<?php
$xml_file = "testing.xml";
$xml_path = XML_PATH . $xml_file;
$contents = file_get_contents($xml_path);
$contents = str_replace("?>", "?>\n<email>myemail@gmail.com</email>", $contents);
print_r($contents);
?>
Keep in mind that trying to pass the resulting XML into anything that expects valid XML will fail horribly.
The real question remains: why would you knowingly want to generate invalid XML in the first place?
Edit: To answer your comment from below:
Can someone explain what is happening here with the ?> is that just hidden text in an XML file at the start of each line?
No, it is not hidden, the ?>
is right here:
<?xml version="1.0"?>
^^
<export>
....
</export>
The PHP code that I added replaces that ?>
with ?>
a new line (\n
) and the XML node that you wanted.