Page 1 of 1

Loading php script and saving output to HTML

Posted: Wed Jul 06, 2005 1:09 pm
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

Posted: Wed Jul 06, 2005 1:11 pm
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.

Posted: Wed Jul 06, 2005 1:15 pm
by jevnin
yeah, I want to create a new HTML file from the output of the php file, not print it to the screen.

Posted: Wed Jul 06, 2005 1:16 pm
by Chris Corbyn
Ooops I wasn't quick enough. I was editting my post while you typed your response ;)

Posted: Wed Jul 06, 2005 5:29 pm
by jevnin
Thank you! It worked :-)