PHP Code to Generate Page Source of a webpage as Document file

By | September 8, 2012

In this article, i am going to explain how to create a document file, which having source code of webpage using php. Using file_get_contents() and html_entities() php functions, source  code of a webpage will be saved. By using header() function, document file will be create with source code of a webpage as contents.

[code type=php]

<fieldset style=”background-color:#666; height:50px; padding:20px;”>
<center><form method=”post” action=””>
URL: <input type=”text” name=”url” />
<input type=”submit” name=”submit” />
</form>
</center>
</fieldset>
<?php
if(isset($_POST[‘submit’]) && isset($_POST[‘url’]))
{
$url=$_POST[‘url’];
$a=file_get_contents($url);
$page = htmlentities($a);
$filename = “source.doc”;
header(‘Content-type: application/vnd.ms-word’);
header(‘Content-Disposition: attachment; filename=’.$filename);
echo $page;
}
?>

[/code]

Leave a Reply

Your email address will not be published. Required fields are marked *