PHP Read dynamically generated (and echoed) HTML in a line?

I have a file that extracts some information from a database and creates some relatively simple dynamic HTML.

The file can then be used by DOMPDF to turn it into a PDF document. DOMDPF uses GET variables to achieve a basic implementation.

ob_start();
include_once("report.php?id=1249642977");

require_once("dompdf/dompdf_config.inc.php");

$dompdf = new DOMPDF();
$dompdf->load_html(ob_get_contents());
$dompdf->render();
$dompdf->stream("sample.pdf", array('Attachment'=>'0'));

ob_end_clean();

I thought I could use something like this to achieve the goal, but it is not surprising that this did not work.

So, how can I read the HTML that is output to the browser if you have to download the file directly to a line for use with the DOMPDF class?

+3
source share
6 answers

Two problems.

-, PHP, , include_once - . id report.php .

-, . , DOMPDF, , PDF . , - :

$dompdf = new DOMPDF();
$dompdf->load_html(ob_get_clean());
$dompdf->render();
$dompdf->stream("sample.pdf", array('Attachment'=>'0'));

, . $dompdf- > .

+5

HTTP- HTML $dompdf:

   <?php
    //...
    $dompdf->load_html(file_get_contents("http://yoursite.net/report.php?id=1249642977"));
   //...
   ?>

, .

+6

BlackAura . File_get_contents, , GET vars ( POST). cURL . :

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://YOURFULLURL.COM/report.php?id=1249642977');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$my_html = curl_exec($ch);
curl_close($ch);

$dompdf = new DOMPDF();
$dompdf->load_html($my_html);
$dompdf->render();
$dompdf->stream("sample.pdf", array('Attachment'=>'0'));

, .

+3

PHP file_get_contents :

$page_html = file_get_contents("page.php?id=number");

$page_html dompdf.

, :)

+1

php, HTML, , HTML. , .

Future Googlers , DOMPDF PHP , :

<script type="text/php">
   //some PHP here
</script>
+1

BlackAura . PDF , .

0

Source: https://habr.com/ru/post/1714626/


All Articles