Viewed   62 times

I'm generating a ton of XML that is to be passed to an API as a post variable when a user click on a form button. I also want to be able to show the user the XML before hand.

The code is sorta like the following in structure:

    $lots of = "php";


<?php } ?>


<?php ?>

      The XML for the user to preview

        <input id="xml" value="theXMLagain" />

My XML is being generated with a few while loops and stuff. It then needs to be shown in the two places (the preview and the form value).

My question is. How do I capture the generated XML in a variable or whatever so I only have to generate it once and then just print it out as apposed to generating it inside the preview and then again inside the form value?


<?php ob_start(); ?>
<?php $xml = ob_get_clean(); ?>
<input value="<?php echo $xml ?>" />??????
Saturday, December 10, 2022

You should use fopen to open a file, read the file with fread to search the wanted variable and then write with fwrite.

$fn = "variables.php"; 
$file = fopen($fn, "w+"); 
$size = filesize($fn); 
$text = fread($file, $size); 
fwrite($file, 'text'); 
Tuesday, December 13, 2022

On some installations, there is a bug in pecl. Find this line;

exec $PHP -C -n -q $INCARG -d date.timezone=UTC -d output_buffering=1 -d variables_order=EGPCS -d safe_mode=0 -d register_argc_argv="On" $INCDIR/peclcmd.php "$@" 

remove the -n

If you want to script it, try:

sed -i "$ s|-n||g" /usr/bin/pecl
Monday, October 24, 2022

To answer your exact question, use the following:

arr=( $(find /path/to/toplevel/dir -type f) )


$ find . -type f
$ arr=( $(find . -type f) )
$ echo ${#arr[@]}
$ echo ${arr[@]}
./test1.txt ./test2.txt ./test3.txt
$ echo ${arr[0]}

However, if you just want to process files one at a time, you can either use find's -exec option if the script is somewhat simple, or you can do a loop over what find returns like so:

while IFS= read -r -d $'' file; do
  # stuff with "$file" here
done < <(find /path/to/toplevel/dir -type f -print0)
Friday, August 26, 2022

If anyone should be interested, i have provided the correct answer:

$soapUrl = "";

$xml_post_string = '<?xml version="1.0" encoding="utf-8"?><soap12:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap12=""><soap12:Body><SearchCollectionPoint xmlns=""><customerID>XXX</customerID><key>XXXXXX-XXXXXX</key><serviceID></serviceID><paramID>0</paramID><address>RiksvŠgen 5</address><postcode>59018</postcode><city>Mantorp</city><maxhits>10</maxhits></SearchCollectionPoint></soap12:Body></soap12:Envelope>';

$headers = array(
"POST /package/package_1.3/packageservices.asmx HTTP/1.1",
"Content-Type: application/soap+xml; charset=utf-8",
"Content-Length: ".strlen($xml_post_string)

$url = $soapUrl;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($ch); 

$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);

$parser = simplexml_load_string($response2);
Thursday, September 29, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :