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 pathcolleges.php
More file actions
64 lines (55 loc) · 2.21 KB
/
colleges.php
File metadata and controls
64 lines (55 loc) · 2.21 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/*
* PHP SimpleXML
* Loading a XML from a file, adding new elements and editing elements
*/
if(file_exists('colleges.xml')) {
$cName = $_POST["cName"];
$address = $_POST["address"];
$postcode = $_POST["postcode"];
$type = $_POST["type"];
$pNumber = $_POST["pNumber"];
// loads XML and returns SimpleXML
$xml = simplexml_load_file('colleges.xml');
//transforming the file in xml format
$xmlFormat = $xml->asXML();
//display element in proper format
echo '<u><b>This is the xml code from colleges.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('college');
$newChild -> addChild('name', $cName.", ");
$newChild -> addChild('address', $address.", ");
$newChild -> addChild('postcode', $postcode.", ");
$newChild -> addChild('type', $type.", ");
$newChild -> addChild('phone', $pNumber." ");
//transfering the object in XML format
$xmlFormat = $xml->asXML();
//display the element in proper format
echo '<u><b>This is the xml code from rss.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 colleges.xml');
}
file_put_contents('colleges.xml', $xml ->asXML() );
writeRSS();
function writeRSS(){
if(file_exists('rss.xml')){
$cName = $_POST["cName"];
$address = $_POST["address"];
$postcode = $_POST["postcode"];
$type = $_POST["type"];
$pNumber = $_POST["pNumber"];
$stringDesc =$cName.", ".$address;
// load XML in simple XML form
$rssxml = simplexml_load_file('rss.xml');
$newChild = $rssxml->channel->addChild('item');
$newChild->addChild('title', "New College added! - ");
$newChild->addChild('link', "https://wad-project-evanmasterson.c9users.io - Click to view College List! - ");
$newChild->addChild('description', $stringDesc);
file_put_contents('rss.xml', $rssxml->asXML());
}
}
?>