Stick an XML value into a variable for file writing
Posted: Wed May 21, 2008 9:40 am
Hello all, I have a question that is complicated in explanation, but I think the solution is going to be like.. one word simple. I'm guessing.
Here's my situation. I have a pdf form developed in Adobe LiveCycle Designer, so it outputs XML values. You can set up a button to fire these values off to a PHP file so that the XML values can be processed.
I have both the form and the PHP file set up, but now I'm trying to write to a .txt file using a retrieved XML field "final1" and to turn the value of that into the contents of the .txt file. Let's look at some stuff.
The form
http://www.cyan-studios.net/posttest/outputtest2.pdf
The .txt file
http://www.cyan-studios.net/posttest/smdownload.txt
The PHP code
Code:
<HTML>
<HEAD>
<TITLE>HTTP Request Dump</TITLE>
</HEAD>
<BODY>
<h1>HTTP Request Dump</h1>
This page sends back to you what your browser or other user-agent submitted to this page.
<h2>HTTP Headers</h2>
<pre>
<?PHP
DumpArray("HEADERS", emu_getallheaders());
?>
</pre>
<h2>Submitted Variables (as parsed by PHP)</h2>
<pre>
<?PHP
echo $content_type;
DumpArray("REQUEST",$_REQUEST);
?>
</pre>
<h2>Raw POST Body</h2>
<pre>
<?PHP
$body = file_get_contents("php://input");
echo strlen($body);
echo " bytes: <br>";
?>
<span style="background-color: #e0e0f0">
<?PHP
while (strlen($body)>60) {
echo substr($body, 0, 60);
echo "\n";
$body = substr($body, 60);
}
echo $body;
?>
</span>
</pre>
</BODY>
</HTML>
<?PHP
# Function DumpArray
##########################################################
function DumpArray($ArrayName,&$Array) {
foreach ($Array as $Key=>$Value){
echo "$Key:\n$Value\n";
} # End of foreach ($GLOBALS as $Key=>$Value)
} # End of function DumpArray
#################################################
function emu_getallheaders() {
foreach($_SERVER as $h=>$v)
if(ereg('HTTP_(.+)',$h,$hp))
$headers[$hp[1]]=$v;
$headers["CONTENT_TYPE"]=$_SERVER["CONTENT_TYPE"];
return $headers;
}
$myFile = "smdownload.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Jallopy";
fwrite($fh, $stringData);
fclose($fh);
?>
You get something like this on the dump:

As you can see from my oh-so artistically fashioned diagram, I just want the value of key "final1", and I want to turn that into a variable. Then, I want to toss that variable in place of the word "Jallopy" in the above code (see the blue text).
Any help's appreciated and shall be rewarded with cake.
Here's my situation. I have a pdf form developed in Adobe LiveCycle Designer, so it outputs XML values. You can set up a button to fire these values off to a PHP file so that the XML values can be processed.
I have both the form and the PHP file set up, but now I'm trying to write to a .txt file using a retrieved XML field "final1" and to turn the value of that into the contents of the .txt file. Let's look at some stuff.
The form
http://www.cyan-studios.net/posttest/outputtest2.pdf
The .txt file
http://www.cyan-studios.net/posttest/smdownload.txt
The PHP code
Code:
<HTML>
<HEAD>
<TITLE>HTTP Request Dump</TITLE>
</HEAD>
<BODY>
<h1>HTTP Request Dump</h1>
This page sends back to you what your browser or other user-agent submitted to this page.
<h2>HTTP Headers</h2>
<pre>
<?PHP
DumpArray("HEADERS", emu_getallheaders());
?>
</pre>
<h2>Submitted Variables (as parsed by PHP)</h2>
<pre>
<?PHP
echo $content_type;
DumpArray("REQUEST",$_REQUEST);
?>
</pre>
<h2>Raw POST Body</h2>
<pre>
<?PHP
$body = file_get_contents("php://input");
echo strlen($body);
echo " bytes: <br>";
?>
<span style="background-color: #e0e0f0">
<?PHP
while (strlen($body)>60) {
echo substr($body, 0, 60);
echo "\n";
$body = substr($body, 60);
}
echo $body;
?>
</span>
</pre>
</BODY>
</HTML>
<?PHP
# Function DumpArray
##########################################################
function DumpArray($ArrayName,&$Array) {
foreach ($Array as $Key=>$Value){
echo "$Key:\n$Value\n";
} # End of foreach ($GLOBALS as $Key=>$Value)
} # End of function DumpArray
#################################################
function emu_getallheaders() {
foreach($_SERVER as $h=>$v)
if(ereg('HTTP_(.+)',$h,$hp))
$headers[$hp[1]]=$v;
$headers["CONTENT_TYPE"]=$_SERVER["CONTENT_TYPE"];
return $headers;
}
$myFile = "smdownload.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Jallopy";
fwrite($fh, $stringData);
fclose($fh);
?>
You get something like this on the dump:

As you can see from my oh-so artistically fashioned diagram, I just want the value of key "final1", and I want to turn that into a variable. Then, I want to toss that variable in place of the word "Jallopy" in the above code (see the blue text).
Any help's appreciated and shall be rewarded with cake.