473,385 Members | 1,453 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.

Stumped

Alright, I've run into a little problem. I have an html file with some
<?php ?> tags and such that need to be evaluated. Some of you probably
already know what I'm getting at.

I need to be able to open the file, make some changes, then execute the
code. I need it to behave like include() or require(). eval() was a
decent solution, but it only supports raw php code.

So what I'm doing is saving the modified code back out to a temp file,
calling include() on the temp file, and then deleting it. Seems like an
awful lot of work.

Is there a way to do this better? Basically an include() that I pass
code to rather than a file pointer?

--
- Thom McGrath
Head of the ZeeTox Project and lead programmer for The ZAZ
Contact me with iChat or AOL Instant Messenger: zazTekcor

Jul 17 '05 #1
10 1563
"Thom McGrath" <th**@thezaz.com> wrote in message
news:2004021319433416807%thom@thezazcom...
Alright, I've run into a little problem. I have an html file with some
<?php ?> tags and such that need to be evaluated. Some of you probably
already know what I'm getting at.

I need to be able to open the file, make some changes, then execute the
code. I need it to behave like include() or require(). eval() was a
decent solution, but it only supports raw php code.

So what I'm doing is saving the modified code back out to a temp file,
calling include() on the temp file, and then deleting it. Seems like an
awful lot of work.

Is there a way to do this better? Basically an include() that I pass
code to rather than a file pointer?

--
- Thom McGrath
Head of the ZeeTox Project and lead programmer for The ZAZ
Contact me with iChat or AOL Instant Messenger: zazTekcor


Ok, I am a little confused, why nit just rename the .html file to .php and
do an include?
If that does not work, I may have a solution for you, but need to understand
you a bit better. can you give example?

or do you just want to eval() html and code? (this is possible)

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #2
On 2004-02-13 20:03:54 -0500, "CountScubula" <me@scantek.hotmail.com> said:
Ok, I am a little confused, why nit just rename the .html file to .php and
do an include?
If that does not work, I may have a solution for you, but need to understand
you a bit better. can you give example?

or do you just want to eval() html and code? (this is possible)


eval() html and code. I can't do an include because the code is a bit
dynamic. It has HTML and PHP mixed in, like a web page file (as that's
pretty much what it is).

--
- Thom McGrath
Head of the ZeeTox Project and lead programmer for The ZAZ
Contact me with iChat or AOL Instant Messenger: zazTekcor

Jul 17 '05 #3
here is some code, I borrowed some pieces:
is will do the eval on a string with/embeded php tags

<?php

$s = "hi <?php print 'john doe'; ?>\n";

print gzenEval($s);

function gzenEvalBuffer($string){ob_start();eval("$string[2];");$return =
ob_get_contents();
ob_end_clean();return $return;}
function gzenEvalPrintBuffer($string) {ob_start();eval("print
$string[2];");$return = ob_get_contents();
ob_end_clean();return $return;}
function gzenEval($string){$string =
preg_replace_callback("/(<\?=)(.*?)\?>/si","gzenEvalPrintBuffer",$string);
return
preg_replace_callback("/(<\?php|<\?)(.*?)\?>/si","gzenEvalBuffer",$string);}

?>

--
Mike Bradley
http://www.gzentools.com -- free online php tools
"Thom McGrath" <th**@thezaz.com> wrote in message
news:2004021320492516807%thom@thezazcom...
On 2004-02-13 20:03:54 -0500, "CountScubula" <me@scantek.hotmail.com> said:
Ok, I am a little confused, why nit just rename the .html file to .php and do an include?
If that does not work, I may have a solution for you, but need to understand you a bit better. can you give example?

or do you just want to eval() html and code? (this is possible)


eval() html and code. I can't do an include because the code is a bit
dynamic. It has HTML and PHP mixed in, like a web page file (as that's
pretty much what it is).

--
- Thom McGrath
Head of the ZeeTox Project and lead programmer for The ZAZ
Contact me with iChat or AOL Instant Messenger: zazTekcor

Jul 17 '05 #4
On 2004-02-13 21:49:20 -0500, "CountScubula" <me@scantek.hotmail.com> said:
here is some code, I borrowed some pieces:
is will do the eval on a string with/embeded php tags


But wouldn't that screw up the scope, because the eval is being
executed inside a function?

for emaple:
$name = 'john doe';
$s = "hi <?php print $name; ?>\n";
print gzenEval($s);

wouldn't that simply output

'hi '

?

--
- Thom McGrath
Head of the ZeeTox Project and lead programmer for The ZAZ
Contact me with iChat or AOL Instant Messenger: zazTekcor

Jul 17 '05 #5
nope, I tested before I posted, it works ok, this use to be part of my
encoders, now I moved all static html into encoded php, so I didn't need
this stub anymore, but thats another story


--
Mike Bradley
http://www.gzentools.com -- free online php tools
"Thom McGrath" <th**@thezaz.com> wrote in message
news:2004021322571616807%thom@thezazcom...
On 2004-02-13 21:49:20 -0500, "CountScubula" <me@scantek.hotmail.com> said:
here is some code, I borrowed some pieces:
is will do the eval on a string with/embeded php tags


But wouldn't that screw up the scope, because the eval is being
executed inside a function?

for emaple:
$name = 'john doe';
$s = "hi <?php print $name; ?>\n";
print gzenEval($s);

wouldn't that simply output

'hi '

?

--
- Thom McGrath
Head of the ZeeTox Project and lead programmer for The ZAZ
Contact me with iChat or AOL Instant Messenger: zazTekcor

Jul 17 '05 #6
"Thom McGrath" <th**@thezaz.com> wrote in message
news:2004021322571616807%thom@thezazcom...
On 2004-02-13 21:49:20 -0500, "CountScubula" <me@scantek.hotmail.com> said:
But wouldn't that screw up the scope, because the eval is being
executed inside a function?

for emaple:
$name = 'john doe';
$s = "hi <?php print $name; ?>\n";
print gzenEval($s);

wouldn't that simply output

'hi '

--
- Thom McGrath
Head of the ZeeTox Project and lead programmer for The ZAZ
Contact me with iChat or AOL Instant Messenger: zazTekcor

oops, I just saw what you typed: $name = 'john doe';
$s = "hi <?php print $name; ?>\n";


$s will be "hi <?php print john doe; ?>\n"
do a print $s; to verify

you would have to do this:
$name = 'john doe';
$s = "hi <?php print \"$name\"; ?>\n";
print gzenEval($s);

now if you wanted to eval the $name durring the eval process this can be
done, bu why, when you can do it before it hits it, since everything is in a
string.

Ok, but if you must, this too can be done, (I do it in my encoder, so an
encoded file can included a non encoded file).

Lets make things real simple, can you post a mini version of what you are
doing, not theory, but bits-o-code?

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #7
On 2004-02-13 23:09:21 -0500, "CountScubula" <me@scantek.hotmail.com> said:
nope, I tested before I posted, it works ok, this use to be part of my
encoders, now I moved all static html into encoded php, so I didn't need
this stub anymore, but thats another story


One last question regarding this code. The regex looks too greedy. For example:

$s = 'Hi <?php print 'John Doe'; ?>. How are you this <?php print
date('l'); ?>?';

Wouldn't that cause trouble? Unless I'm missing something, the regex
would match from the first <?php to the second ?>.

--
- Thom McGrath
Head of the ZeeTox Project and lead programmer for The ZAZ
Contact me with iChat or AOL Instant Messenger: zazTekcor

Jul 17 '05 #8
On 2004-02-13 23:18:28 -0500, "CountScubula" <me@scantek.hotmail.com> said:
you would have to do this:
$name = 'john doe';
$s = "hi <?php print \"$name\"; ?>\n";
print gzenEval($s);

now if you wanted to eval the $name durring the eval process this can be
done, bu why, when you can do it before it hits it, since everything is in a
string.

Ok, but if you must, this too can be done, (I do it in my encoder, so an
encoded file can included a non encoded file).

Lets make things real simple, can you post a mini version of what you are
doing, not theory, but bits-o-code?


No, I can't. It's a) rather protected and b) rather complex. What I can
tell you is that this is for a template engine. My users would have the
ability to do something like $theme->ReadTemplate("Site Header"); to
load the site's header into some variable.

The header may contain php code embedded with plain html, so printing
the variable won't work. The other possibility is that the template
will contain pure php code which can be loaded a similar way. Although
a dumb possibility, I can't control what my users will want to do.

So I want to provide my users a function like

Execute($theme->ReadTemplate("Site Header"));

to handle this. There is a good possiblity that the code in the
template will need variables not in the template. So what I am doing
now is rather messy:

include(MakeInclude($theme->ReadTemplate("Site Header")));

which takes care of the job, but every time the template is needed, a
temp file will be created/overwritten, then included.

I am under the impression what I'm doing now might be the only or best
option, but I'm hoping somebody will have something better.

--
- Thom McGrath
Head of the ZeeTox Project and lead programmer for The ZAZ
Contact me with iChat or AOL Instant Messenger: zazTekcor

Jul 17 '05 #9
"Thom McGrath" <th**@thezaz.com> wrote in message
news:2004021323282775249%thom@thezazcom...

No, I can't. It's a) rather protected and b) rather complex. What I can
tell you is that this is for a template engine. My users would have the
ability to do something like $theme->ReadTemplate("Site Header"); to
load the site's header into some variable.

OK, so, would it be fair to say this:

$name = "john doe";

$s = "<B><?php print \$name; ?></B>"; // only \$ needed for direct string
not from file()
or
$s = file("localfile.template");

magicEval($s);

and you would like to have $name evaled in the magicEval, thus including a
file would work?

if so, let me know, email me at: info at gzentools dot com
--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #10
The cleanest way is probably to do a
include("http://localhost/code.php?some_params...") where code.php outputs
the code. Makes it easier to debug since you can just call up the PHP code
in your browser.

Be sure to compare $_SERVER['SERVER_ADDR'] to $_SERVER['REMOTE_ADDR'] so
that you don't reveal your PHP code to the world!

Uzytkownik "Thom McGrath" <th**@thezaz.com> napisal w wiadomosci
news:2004021319433416807%thom@thezazcom...
Alright, I've run into a little problem. I have an html file with some
<?php ?> tags and such that need to be evaluated. Some of you probably
already know what I'm getting at.

I need to be able to open the file, make some changes, then execute the
code. I need it to behave like include() or require(). eval() was a
decent solution, but it only supports raw php code.

So what I'm doing is saving the modified code back out to a temp file,
calling include() on the temp file, and then deleting it. Seems like an
awful lot of work.

Is there a way to do this better? Basically an include() that I pass
code to rather than a file pointer?

--
- Thom McGrath
Head of the ZeeTox Project and lead programmer for The ZAZ
Contact me with iChat or AOL Instant Messenger: zazTekcor

Jul 17 '05 #11

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

Similar topics

10
by: Manny | last post by:
I have a web form "Page1.asp" and it reads data from a database, does some calculations, and displays the records in pages. Works fine. I have a button that displays on the page, defined as...
1
by: Sharron | last post by:
This problem has me completely stumped...everyone on the net seems to have this problem but I don't understand what they are talking about. I know my code is correct it compiles fine but when I try...
0
by: Sharron | last post by:
Hello, This problem has me completely stumped...everyone on the net seems to have this problem but I don't understand what they are talking about. I know my code is correct it compiles fine but...
3
by: Chris | last post by:
I have yet to understand or get a response on the issue I'm having. I'm taking an asp web application and migrating it from Windows 2K to 2003. I have the new website location (2003) settings...
1
by: Kent Wolf | last post by:
I have some code that worked just fine in Access 97 with Word 97 in Windows NT 4.0. We upgraded one of our OS's to Windows XP. Now, the code won't work. I got an error that said something...
5
by: darrel | last post by:
I'm still a bit stumped on how to load a usercontrol, and then pass a property value (or variable value) to it. Here's what I'm using to load the UC: localCUstomControl.ascx.vb...
0
by: Vince Campanile | last post by:
Ive got what must bea very basic question, but its got ne thouroughly stumped. Im writing a very simple application in Visual Basic.Ne 2003, thats using a data adapter hooked up to an Access...
8
by: Gary | last post by:
I'm using an Act database. I was stuck on this a year ago and am still having trouble. I have three bits of code like so : - act.CActAppObj objACT = new act.CActAppObj(); act.CAIBaseView...
3
by: Randy Magruder | last post by:
Hi all, I hope someone here can diagnose what I'm seeing because I'm stumped. I have an asp.net 1.1 application with a login page. I have loaded up the Page_Load( ) with trace messages and...
1
by: slamtart | last post by:
Hi everyone, Stumped for awhile with this one. Not sure what to do next. Basically, I have a laptop computer which I use for work. Prior to around May of this year, there's no trick to...
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: 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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.