2,3c2
< // csv_via_xml_report.php
< // Create CSV report via XML input
---
> // xml_to_csv.php
5,53c4,5
< // September, 2018
<
< $jobbits="Job Description Goes Here"; // fill this in
<
< function oursimplexml_load_file($inxml) {
< if (isset($_GET['generic']) || isset($_POST['generic'])) {
< return simplexml_load_file($inxml);
< } else {
< $outrpts=explode(".xm", str_replace(".XML",".xml",str_replace(".Xml",".xml",$inxml)));
< $outrpt="";
< if (sizeof($outrpts) > 1) {
< $bz="";
< $prebz="";
< $outrpt=$outrpts[0] . $prebz . $bz . ".csv";
< while (file_exists($outrpts[0] . ".csv" . $bz)) {
< if (("" . $bz) == "") {
< $prebz="_";
< $bz=1;
< } else {
< $bz++;
< }
< $outrpt=$outrpts[0] . $prebz . $bz . ".csv";
< }
< }
< // Start of business logic piecing together CSV report ...
< $cont=file_get_contents($inxml);
< $detailrec='';
< $detailrec='"col1value","col2value"'; // you do more in depth work to get to this point via $cont
< if (trim($detailrec) != "") {
< $headerrec='"col1label","col2label"'; // you do more in depth work to get a header record as required via $cont
< if ($outrpt != "" && 1 == 1) {
< if ($headerrec != "") { $headerrec.="\n"; }
< file_put_contents($outrpt, $headerrec . $detailrec);
< exit;
< } else {
< if ($headerrec != "") { $headerrec.="
"; }
< echo "
" . $headerrec . $detailrec . "
";
< return null;
< }
< }
< // End of business logic piecing together CSV report
< return null;
< }
< }
<
< $genextra="";
< if (isset($_GET['generic']) || isset($_POST['generic'])) {
< $genextra="";
< }
---
> // August, 2018
> // Thanks to https://edmondscommerce.github.io/php/generic-xml-to-csv-converter.html
61,88d12
< // add in file(spec) considerations here
< if (strpos(str_replace("+"," ",urldecode($_GET['xml'])), "*") !== false || strpos(str_replace("+"," ",urldecode($_GET['xml'])), "%") !== false || strpos(str_replace("+"," ",urldecode($_GET['xml'])), "?") !== false) {
< $htmlis="XML to CSV " . $jobbits . " Report Run ...
";
< foreach (glob(str_replace("+"," ",urldecode($_GET['xml']))) as $xmlfil) {
< $bz="";
< $prebz="";
< $outrpts=explode(".xm", str_replace(".XML",".xml",str_replace(".Xml",".xml",$xmlfil)));
< $outrpt=$outrpts[0] . $prebz . $bz . ".csv";
< while (file_exists($outrpts[0] . ".csv" . $bz)) {
< if (("" . $bz) == "") {
< $prebz="_";
< $bz=1;
< } else {
< $bz++;
< }
< $outrpt=$outrpts[0] . $prebz . $bz . ".csv";
< }
< exec("curl " . "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0] . '?xml=' . urlencode($xmlfil));
< if (file_exists($outrpt)) {
< $htmlis=str_replace("","Read " . $xmlfil . " as basis for" . " " . $jobbits . " report " . $outrpt . " for your perusal.
",$htmlis);
< } else {
< $htmlis=str_replace("","Could not read " . $xmlfil . " as basis for" . " " . $jobbits . " report " . $outrpt . " successfully, alas.
",$htmlis);
< }
< }
< echo $htmlis;
< exit;
< }
< // end of file(spec) considerations above
99c23
< $xml = oursimplexml_load_string($xmlstr);
---
> $xml = simplexml_load_string($xmlstr);
106c30
< $xml = oursimplexml_load_file(urldecode($_GET['xml']));
---
> $xml = simplexml_load_file(urldecode($_GET['xml']));
109,136d32
< // add in file(spec) considerations here
< if (strpos(str_replace("+"," ",urldecode($_POST['xml'])), "*") !== false || strpos(str_replace("+"," ",urldecode($_POST['xml'])), "%") !== false || strpos(str_replace("+"," ",urldecode($_POST['xml'])), "?") !== false) {
< $htmlis="XML to CSV " . $jobbits . " Report Run ...
";
< foreach (glob(str_replace("+"," ",urldecode($_POST['xml']))) as $xmlfil) {
< $bz="";
< $prebz="";
< $outrpts=explode(".xm", str_replace(".XML",".xml",str_replace(".Xml",".xml",$xmlfil)));
< $outrpt=$outrpts[0] . $prebz . $bz . ".csv";
< while (file_exists($outrpts[0] . ".csv" . $bz)) {
< if (("" . $bz) == "") {
< $prebz="_";
< $bz=1;
< } else {
< $bz++;
< }
< $outrpt=$outrpts[0] . $prebz . $bz . ".csv";
< }
< exec("curl " . "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . explode("?",$_SERVER['REQUEST_URI'])[0] . '?xml=' . urlencode($xmlfil));
< if (file_exists($outrpt)) {
< $htmlis=str_replace("","Read " . $xmlfil . " as basis for" . " " . $jobbits . " report " . $outrpt . " for your perusal.
",$htmlis);
< } else {
< $htmlis=str_replace("","Could not read " . $xmlfil . " as basis for" . " " . $jobbits . " report " . $outrpt . " successfully, alas.
",$htmlis);
< }
< }
< echo $htmlis;
< exit;
< }
< // end of file(spec) considerations above
147c43
< $xml = oursimplexml_load_string($xmlstr);
---
> $xml = simplexml_load_string($xmlstr);
154c50
< $xml = oursimplexml_load_file(urldecode($_POST['xml']));
---
> $xml = simplexml_load_file(urldecode($_POST['xml']));
159d54
< if ($xml) {
181c76
< echo "XML to CSV " . $jobbits . " Report - RJM Programming - September, 2018
---
> echo "XML to CSV - RJM Programming - August, 2018
185,187c80,82
<