Loading php script and saving output to HTML

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jevnin
Forum Newbie
Posts: 3
Joined: Wed Jul 06, 2005 1:03 pm

Loading php script and saving output to HTML

Post by jevnin »

Here's a n00b question for you...

I can't for the life of me figure out how to call a PHP file from my main PHP file and save the result into an HTML file. I've tried everything, but surely there's a way to do this...help! Thanks in advance.

-j
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

You want to physically create a file rather than sending the output back to the browser?

A shell access method:

Code: Select all

system('php thescript.php > thehtmlfile.html');
A 100% PHP method:

Code: Select all

$data = file_get_contents('http://localhost/thescript.php?args=values'); //http portion in tact so apache runs it
$handle = fopen('thehtmlfile.html', 'w');
fwrite($data, $handle);
fclose($handle);
EDIT | Addeell access method:

Code: Select all

system('php thescript.php > thehtmlfile.html');
A 100% PHP method:

Code: Select all

$data = file_get_contents('http://localhost/thescript.php?args=values'); //http portion in tact so apache runs it
$handle = fopen('thehtmlfile.html', 'w');
fwritocalhost/thescript.php?args=values'); //http portion in tact so apache runs it
$handle = fopen('thehtmlfile.html', 'w');
fwrite($data, $handle);
fclose]
system('php thescript.php > thehtmlfile.html');
A 100% PHP method:

Code: Select all

$data = file_get_contents('http://localhost/thescript.php?args=values'); //http portion in tact so apache runs it
$handle = fopen('thehtmlfile.html', 'w');
fwrite($data, $handle);
fclose($handle);
[/php:1:f502g the output back to the browser?

A shell access method:

Code: Select all

system('php thescript.php > thehtmlfile.html');
A 100% PHP method:

Code: Select all

$data = file_get_contents('http://localhost/thescript.php?args=values'ally create a file rather than sending the output back to the browser?

A shell access method:

Code: Select all

system('php thescript.php > thehtmlfile.html');
A 100% PHP method:

Code: Select all

$data = file_get_contents('httally create a file rather than sending the output back to the browser?

A shell access method:

Code: Select all

system('php thescript.php > thehtmlfile.html');
A 100% PHP method:

Code: Select all

$data = file_get_contents('http://localhost/thescript.php?argthod:

Code: Select all

system('php thescript.php > thehtmlfile.html');
A 100% PHP method:

Code: Select all

$data = file_get_contents('http://localhost/thescript.php?args=values'); //http portion in tact so apache runs it
$handle = fopen('thehtmlfile.html', 'w');
fwrite($data, $handle);
fclose($handle);
EDIT | Added some examples.
system('php thescript.php > thehtmlfile.html');


A 100% PHP method:

Code: Select all

$data = file_get_contents('http://localhost/thescript.php?args=values'); //http portion in tact so apache runs it
$handle = fopen('thehtmlfile.html', 'w');
fwrite($data, $handle);
fclose($handle);
EDIT | Added some examples.
Last edited by Chris Corbyn on Wed Jul 06, 2005 1:15 pm, edited 1 time in total.
jevnin
Forum Newbie
Posts: 3
Joined: Wed Jul 06, 2005 1:03 pm

Post by jevnin »

yeah, I want to create a new HTML file from the output of the php file, not print it to the screen.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Ooops I wasn't quick enough. I was editting my post while you typed your response ;)
jevnin
Forum Newbie
Posts: 3
Joined: Wed Jul 06, 2005 1:03 pm

Post by jevnin »

Thank you! It worked :-)
Post Reply