Dynadot

View the output of your PHP script in Internet Explorer without a server

Spaceship Spaceship
Watch
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:

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
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
just so you know, the command line command "php" seems like you'd already have php installed (and possibly a server). this i think is by default on macs (and possibly linux, not sure) - but it doesn't work on windows (as far as i know).

if you are on windows and don't want to install a whole server, try xampp - it's a portable server app (so no installation needed), where you just run it and it creates a localhost server (accessible only to you) to run any webpages you may want.
 
0
•••
No, I only have php installed on my system for debugging purposes. Normally I just upload the scripts to a web server, but sometimes I don't have access to the internet or I don't need any server functionality (If I did, chances are I would be using a remote server anyway.)
 
0
•••
0
•••
I, too, use XAMPP.

Just reinstalled it so that I can do some WordPress
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back