NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page View the output of your PHP script in Internet Explorer without a server

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search
7 members in live chat ~  


Reply
 
LinkBack Thread Tools
Old 12-21-2009, 03:33 PM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Mar 2006
Location: (US) Missouri
Posts: 70
Hobnob is on a distinguished road
 



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


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 Code:
ob_start();

function 
DisplayHtmlOutput() {
    
$output ob_get_contents();
    
ob_end_clean();
    
    
$tmpfname tempnam(sys_get_temp_dir(), 'php');
    
$tmpfname.= '.html';
    
    
$handle fopen($tmpfname"w");
????: NamePros.com http://www.namepros.com/code/629889-view-output-your-php-script-internet.html
    
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 Code:
<?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
Hobnob is offline   Reply With Quote
Old 12-21-2009, 04:02 PM   #2 (permalink)
Senior Member
 
nasaboy007's Avatar
Join Date: Jul 2005
Location: NJ
Posts: 1,219
nasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud of
 



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.
nasaboy007 is offline   Reply With Quote
Old 12-21-2009, 06:45 PM THREAD STARTER               #3 (permalink)
NamePros Member
Join Date: Mar 2006
Location: (US) Missouri
Posts: 70
Hobnob is on a distinguished road
 



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.)
Hobnob is offline   Reply With Quote
Old 01-05-2010, 06:01 PM   #4 (permalink)
New Member
Join Date: Sep 2009
Posts: 2
Blockeel is an unknown quantity at this point
 



i use XAMPP

very useful
Blockeel is offline   Reply With Quote
Old 01-05-2010, 07:08 PM   #5 (permalink)
NamePros Regular
 
Ookie's Avatar
Join Date: Jan 2009
Location: South Australia
Posts: 906
Ookie is a splendid one to beholdOokie is a splendid one to beholdOokie is a splendid one to beholdOokie is a splendid one to beholdOokie is a splendid one to beholdOokie is a splendid one to beholdOokie is a splendid one to beholdOokie is a splendid one to behold
 



Adoption Breast Cancer
I, too, use XAMPP.

Just reinstalled it so that I can do some WordPress
Ookie is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 07:30 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger