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
<?php
$xmlLoc = $_GET['g'];

$file = fopen($xmlLoc, "w+") or die("Can't open XML file");

// create array containing common tags that get destroyed
// these are unlikely to crop up anywhere else in an XML since they are so specific
$oldChars = array("&lt;p&gt;", "&lt;/p&gt;", "&lt;br/&gt;");

// create array containing desired replacements for above mangled tags
// taking care to ensure that the relative positions of the tags between
// arrays match correctly.
$newChars = array("<![CDATA[<p>", "</p>]]>", "<br/>");

// use the ever-so-handy php replace string function to replace
// every instance of a mangled tag with a corrected version
$xmlString = str_replace($oldChars, $newChars, $HTTP_RAW_POST_DATA);


// hopefully by here - the mangled tags will be properly reformatted and
// the xml can saved back to the server correctly
// the only thing i don't know how to do is to preserve the visual
// spacing structure so if you open the xml in dreamweaver or text
// editor, it still retains it's original well laid out form.
if(!fwrite($file, $xmlString)){
print "<?xml version=\"1.0\" encoding=\"utf-8\"?><output>Error writing to XML-file</output>";
}else{
print "<?xml version=\"1.0\" encoding=\"utf-8\"?><output>XML File Saved</output>";
}
fclose($file);
?>