geeeeeeeek geeeeeeeek - 1 year ago 50
PHP Question

Trying to generate a html file from PHP code

I have a PHP program from OpenEMR that prints context to the console in HTML format. I wanted to save whatever it prints to another html file. I am not very familiar with PHP and front end technologies. Does anyone know a simple way to make it work? Thanks a lot.

Below is the code detail:

foreach($newpatient as $patient){
$inclookupres = sqlStatement("select distinct formdir from forms where pid='".$pids[$iCounter]."'");
while($result = sqlFetchArray($inclookupres)) {
include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");

print "<div id='superbill_patientdata'>";
print "<h1>".xlt('Patient Data').":</h1>";
printRecDataOne($patient_data_array, getRecPatientData ($pids[$iCounter]), $N);
print "</div>";

print "<div id='superbill_insurancedata'>";
print "<h1>".xlt('Insurance Data').":</h1>";
print "<h2>".xlt('Primary').":</h2>";
printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"primary"), $N);
print "<h2>".xlt('Secondary').":</h2>";
printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"secondary"), $N);
print "<h2>".xlt('Tertiary').":</h2>";
printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"tertiary"), $N);
print "</div>";

print "<div id='superbill_billingdata'>";
print "<h1>".xlt('Billing Information').":</h1>";
if (count($patient) > 0) {
$billings = array();
echo "<table width='100%'>";
echo "<tr>";
echo "<td class='bold' width='10%'>".xlt('Date')."</td>";
echo "<td class='bold' width='20%'>".xlt('Provider')."</td>";
echo "<td class='bold' width='40%'>".xlt('Code')."</td>";
echo "<td class='bold' width='10%'>".xlt('Fee')."</td></tr>\n";
$total = 0.00;
$copays = 0.00;
//foreach ($patient as $be) {

$ta = split(":",$patient);
$billing = getPatientBillingEncounter($pids[$iCounter],$ta[1]);

$billings[] = $billing;
foreach ($billing as $b) {
// grab the date to reformat it in the output
$bdate = strtotime($b['date']);

echo "<tr>\n";
echo "<td class='text' style='font-size: 0.8em'>" . oeFormatShortDate(date("Y-m-d",$bdate)) . "<BR>" . date("h:i a", $bdate) . "</td>";
echo "<td class='text'>" . text($b['provider_name']) . "</td>";
echo "<td class='text'>";
echo text($b['code_type']) . ":\t" . text($b['code']) . "&nbsp;". text($b['modifier']) . "&nbsp;&nbsp;&nbsp;" . text($b['code_text']) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo "</td>\n";
echo "<td class='text'>";
echo oeFormatMoney($b['fee']);
echo "</td>\n";
echo "</tr>\n";
$total += $b['fee'];
// Calculate the copay for the encounter
$copays = getPatientCopay($pids[$iCounter],$ta[1]);
echo "<tr><td>&nbsp;</td></tr>";
echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Sub-Total')."</td><td class='text'>" . oeFormatMoney($total + abs($copays)) . "</td></tr>";
echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Copay Paid')."</td><td class='text'>" . oeFormatMoney(abs($copays)) . "</td></tr>";
echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Total')."</td><td class='text'>" . oeFormatMoney($total) . "</td></tr>";
echo "</table>";
echo "<pre>";
echo "</pre>";
echo "</div>";

Answer Source


    $page= ob_get_contents();
    if ($fp = fopen('../page.htm', 'w+')) {
    fwrite ($fp, $page);