Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get html code into a php variable

Tags:

php

I'm don't use PHP that much and right now I'm stuck at a problem. I need to save the site of a webbrowser as a pdf. I'm using right now mPDF (which was suggested in a wiki of stackoverflow) and it seems to work pretty well (I just have simply write a short html code into a php variable and then created the pdf).

But now I must get the html code of the actual site in the browser and save it then into a php variable. How can I do that?

like image 996
mkn Avatar asked Sep 24 '10 07:09

mkn


2 Answers

If I understand you correctly, you can store page contents into php variable like this:

ob_start();

// your html code goes here

$contents = ob_get_contents();
ob_end_clean();

// see the contents now
echo $contents;
like image 175
Sarfraz Avatar answered Oct 13 '22 00:10

Sarfraz


You can probably fetch the remote content via PHPs file_get_contents()-function:

$html = file_get_contents('http://example.org');

If this does not work, make sure that you have allow_url_fopen enabled in your php.ini.

like image 23
jwueller Avatar answered Oct 13 '22 01:10

jwueller