Skip to content Skip to sidebar Skip to footer

create html file in php

Create html file in php:-
    In php program we can easy to create more html files in a single click, and generate different code in every auto created html files.  We can create a file using "fopen"  and write content after creating the file using "fwrite".


Syntax for create a file:-


$myFile="filepath".extension";
$fh = fopen($myFile, 'a+') or exit("Error creation");
        ------
        ------
        $StringData="file Content";
        fwrite($fh, $stringData);


Example:-


<?php
for($i=1;$i<30;$i++)
{
$myFile="3dpage/3dpg".$i.".html";
$fh = fopen($myFile, 'a+') or exit("<font color='red'>Please Create a directory name:3dpage");
$stringData = "
<html>
<head>
<title>Very hot and Nice Wallpapers</title>
</head>
<body>
<div style='position:absolute;left: 20;top: 120px;width:201px;height:20px;'>
<img src='http://file1.hpage.com/011089/04/bilder/dbig_".$i.".jpg' width=750 height=700>
</div>
</body>
</html>";
fwrite($fh, $stringData);
}
echo "<font color='green'><b>29 Files were created successfully";
?>





Output:-

php generate html files

php file created
Advertisement


Post a Comment for "create html file in php"