Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Php Programming Code Examples

Php > HTML and Php Code Examples

Creating a html page on the fly

Creating a html page on the fly <? //create an html file and redirect to it //set some basic html content $sHTML_Header = "<html><head><title>Test an html page</title></head><body>"; $sHTML_Content = "<h2><center>This is a Test Page</center><h2><br /><hr />"; $sHTML_Footer = "</body></html>"; $filename = "test.html"; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'w')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $sHTML_Header) === FALSE) { echo "Cannot write to file ($filename)"; exit; }else{ //file is ok so write the other elements to it fwrite($handle, $sHTML_Content); fwrite($handle, $sHTML_Footer); } fclose($handle); }else{ echo "The file $filename is not writable"; } //redirect the user to the html page header("location:$filename"); ?>