This repository was archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontact.php
More file actions
40 lines (33 loc) · 1.37 KB
/
contact.php
File metadata and controls
40 lines (33 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/*
* PHP SimpleXML
* Loading a XML from a file, adding new elements and editing elements
*/
$contact_email = Trim(stripslashes($_POST["contact_email"]));
$contact_name = Trim(stripslashes($_POST["contact_name"]));
$contact_message = Trim(stripslashes($_POST["contact_message"]));
if(file_exists('contact.xml')) {
// loads XML and returns SimpleXML
$xml = simplexml_load_file('contact.xml');
//transforming the file in xml format
$xmlFormat = $xml->asXML();
//display element in proper format
echo '<u><b>This is the xml code from contact.xml:</b></u>
<br /><br />
<pre>' . htmlentities($xmlFormat, ENT_COMPAT | ENT_HTML401, "ISO-8859-1") . '</pre><br /><br />';
//adding new child to XML
$newChild = $xml->addChild('details');
$newChild -> addChild('email', $contact_email);
$newChild -> addChild('name', $contact_name);
$newChild -> addChild('message', $contact_message);
//transfering the object in XML format
$xmlFormat = $xml->asXML();
//display the element in proper format
echo '<u><b>This is the xml code from contact.xml with new elements added:</b></u>
<br /><br />
<pre>' . htmlentities($xmlFormat, ENT_COMPAT | ENT_HTML401, "ISO-8859-1") . '</pre>';
} else{
exit('Failed to open contact.xml');
}
file_put_contents('contact.xml', $xml ->asXML() );
?>