【问题标题】:Trying to generate a html file from PHP code [closed]尝试从 PHP 代码生成 html 文件 [关闭]
【发布时间】:2016-05-27 21:47:21
【问题描述】:

我有一个来自 OpenEMR 的 PHP 程序,它以 HTML 格式将上下文打印到控制台。我想将它打印的任何内容保存到另一个 html 文件中。我对 PHP 和前端技术不是很熟悉。有谁知道使它工作的简单方法?非常感谢。

下面是代码细节:

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>";
            //print_r($billings);
            echo "</pre>";
        }
        echo "</div>";

【问题讨论】:

  • 将该代码复制到 php 文件中,例如创建 index.php 并粘贴其中的代码,将 index.php 移动到您的服务器中,以便在您的机器上进行测试,您可以使用 wampserver.com/en 然后访问你的浏览器,例如localhost/your_project/index.php 你去
  • @LuisCardenas 感谢您的评论。它在我的本地主机上运行良好;我想要做的实际上只是将这里打印的任何内容保存到 html 文件中。你知道我该怎么做吗?
  • 你用什么软件来运行这个php代码?
  • @LuisCardenas 我只是使用 Notepad++ 来编辑它,因为我之前没有开发任何 PHP 程序。
  • 您可以使用输出缓冲。 PHP 有一些函数可以用来保存到文件中。

标签: php html frontend


【解决方案1】:
    <?php
ob_start();

/* 你的代码 */

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

ob_end_flush();
?>

【讨论】:

  • 非常感谢!完美解决了我的问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-27
  • 2015-03-15
  • 2014-06-29
相关资源
最近更新 更多