473,385 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

run php on a script, from a script

Hi

I would like to know if the following is possible and how to do it:

1)
I have a "template" .php file on my server, say template.php.
It contains some PHP instructions and some HTML

2)
I also have a script, script.php

3)
When script.php runs, I want it to run php on template.php, and write
the resulting html output to a file.

I need to say something like:

<?php

runphp ( 'template.php', 'htmloutput.html' );

?>

and obtain a file, htmloutput.html, with the result of php having run
template.php (hope I'm being clear).

The problem is, of course, that the runphp function doesn't exist so
what is the way to do it?

Thanks
Fred

Feb 8 '06 #1
5 1327
d
"Fred Paris" <no**@nono.invalid> wrote in message
news:mr********************************@4ax.com...
Hi

I would like to know if the following is possible and how to do it:

1)
I have a "template" .php file on my server, say template.php.
It contains some PHP instructions and some HTML

2)
I also have a script, script.php

3)
When script.php runs, I want it to run php on template.php, and write
the resulting html output to a file.

I need to say something like:

<?php

runphp ( 'template.php', 'htmloutput.html' );

?>

and obtain a file, htmloutput.html, with the result of php having run
template.php (hope I'm being clear).

The problem is, of course, that the runphp function doesn't exist so
what is the way to do it?

function runphp($in_fn, $out_fn) {
ob_start();
include($in_fn);
$c=ob_get_contents();
ob_end_clean();
$fp=fopen($out_fn, "wb");
fwrite($fp, $c);
fclose($fp);
}

That's very simple, of course. If something isn't exactly right in how it's
called, it'll fail most spectactularly :) It gives you the general jist,
though - using output buffering to capture the output of a given script, and
then storing that output in a file.

Let me know if there's something you don't understand.

dave

Thanks
Fred

Feb 8 '06 #2

On Wed, 08 Feb 2006 16:33:41 GMT, "d" <d@example.com> wrote:
function runphp($in_fn, $out_fn) {
ob_start();
include($in_fn);
$c=ob_get_contents();
ob_end_clean();
$fp=fopen($out_fn, "wb");
fwrite($fp, $c);
fclose($fp);
}

That's very simple, of course. If something isn't exactly right in how it's
called, it'll fail most spectactularly :) It gives you the general jist,
though - using output buffering to capture the output of a given script, and
then storing that output in a file.

Let me know if there's something you don't understand.


Thanks !
I'll try that !

Feb 8 '06 #3
On 2006-02-08, Fred Paris <no**@nono.invalid> wrote:
2)
I also have a script, script.php

3)
When script.php runs, I want it to run php on template.php, and write
the resulting html output to a file.


use "ob_start"(etc...) to capture output and "require" to run the external
php script.

--

Bye.
Jasen
Feb 9 '06 #4
On Thu, 09 Feb 2006 10:48:35 +0200, Jasen Betts <ja***@free.net.nz> wrote:
On 2006-02-08, Fred Paris <no**@nono.invalid> wrote:
2)
I also have a script, script.php

3)
When script.php runs, I want it to run php on template.php, and write
the resulting html output to a file.


use "ob_start"(etc...) to capture output and "require" to run the
external
php script.


There is another way to do it. You can eval() the code inside template.php.

<?php
$fc = file_get_contents("template.php");
$result = eval(" ?>".$fc."<?php ");
$fh = fopen("resultfile.html", w);
fwrite($fh, $result);
fclose($fh);
?>
Feb 9 '06 #5
d
"Albe" <al**@ambientatom.co.za> wrote in message
news:op***************@equus.up.ac.za...
On Thu, 09 Feb 2006 10:48:35 +0200, Jasen Betts <ja***@free.net.nz> wrote:
On 2006-02-08, Fred Paris <no**@nono.invalid> wrote:
2)
I also have a script, script.php

3)
When script.php runs, I want it to run php on template.php, and write
the resulting html output to a file.


use "ob_start"(etc...) to capture output and "require" to run the
external
php script.


There is another way to do it. You can eval() the code inside
template.php.

<?php
$fc = file_get_contents("template.php");
$result = eval(" ?>".$fc."<?php ");
$fh = fopen("resultfile.html", w);
fwrite($fh, $result);
fclose($fh);
?>


Using eval() is never the way forward :) If you find eval is your saviour,
you've done something wrong :)
Feb 9 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Mike Daniel | last post by:
I am attempting to use document.write(pageVar) that displays a new html page within a pop-up window and the popup is failing. Also note that pageVar is a complete HTML page containing other java...
1
by: bayouprophet | last post by:
Cant get menu script to to put linked page in the same frame. I am new to Java and I am wondering what am I doing wrong? below are my java applet file, frame.html file, and my text file and one...
1
by: Allen | last post by:
I am trying to add an additional photo/hyperlink to the company web site (I didn't create it) without any luck. The mouseover feature 'highlights' pics by swapping them with another pic using this...
3
by: Water Cooler v2 | last post by:
Questions: 1. Can there be more than a single script block in a given HEAD tag? 2. Can there be more than a single script block in a given BODY tag? To test, I tried the following code. None...
2
by: bilaribilari | last post by:
Hi all, I am using Tidy (C) for parsing html pages. I encountered a page that has some script as follows: <script> .... var abc = "<script>some stuff here</" + "script>"; .... </script>
19
by: thisis | last post by:
Hi All, i have this.asp page: <script type="text/vbscript"> Function myFunc(val1ok, val2ok) ' do something ok myFunc = " return something ok" End Function </script>
3
by: rsteph | last post by:
I have a script that shows the time and date. It's been working on my site for quite a while now. Suddenly it stops showing up, after getting my drop down menu to work. If I put text between the...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
7
by: imtmub | last post by:
I have a page, Head tag Contains many Scripts and style sheet for Menu and Page. This code working fine and displaying menus and page as i wanted. Check this page for reference....
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.