- Impact
- 5
I needed to preview the output of one of my php scripts as HTML but I didn't want to download and install a server on my computer so I came up with this quick solution, hopefully it can help someone else out:
Just save the above code to a file and include it at the top of the script you want to view in IE. Example:
Then run the php script from command line:
PHP:
ob_start();
function DisplayHtmlOutput() {
$output = ob_get_contents();
ob_end_clean();
$tmpfname = tempnam(sys_get_temp_dir(), 'php');
$tmpfname.= '.html';
$handle = fopen($tmpfname, "w");
fwrite($handle, $output);
fclose($handle);
$ie = new COM('internetexplorer.application');
$ie->visible = true;
$ie->navigate($tmpfname);
unlink($tmpfname);
}
register_shutdown_function('DisplayHtmlOutput');
Just save the above code to a file and include it at the top of the script you want to view in IE. Example:
PHP:
<?php
include "phpviewer.php";
$name = 'Robert.';
?>
<html>
<head>
<title>This is just a test web page...</title>
</head>
<body>
Hello, <?php echo $name; ?>!
</body>
</html>
Then run the php script from command line:
Code:
php myscript.php