开发者

get html code into a php variable

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 se开发者_运维问答ems 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?


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;


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.


This is probably over-kill, but you can try using SimpleHTML DOM which can load a remote website and extract out its HTML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜