473,761 Members | 4,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using echo but need something to execute php code

I have some code that loads up some php/html files and does a few things to
them and ultimately returns an html file with some php code in it. I then
pass that file onto the user by using echo. Of course then the file doesn't
get seen by the user.

Is there any command that essentially executes the code and then echo's it?

something that will take a string like

'<body>blah<?ph p echo 'Hello'; ?></body>' and actually interpret the php
code?

e.g., doing

echo '<body>blah<?ph p echo 'Hello'; ?></body>';

does me no good caues the php code isn't interpreted.

Saving it to a file and then redirecting the user to that file so it will be
executed seems like a roundabout way and causes more problems.
essentially I am trying to include php/html files in one another but I need
to do some parsing on them first. I'd rather not do something like
file_get_conten ts($Page)
parse($Page)
save($Page)
include "$Page"
as it seems uncessary to have to write the page to disk just to include it.

At

http://us2.php.net/include/
"Another way to "include" a PHP file into a variable is to capture the
output by using the Output Control Functions with include(). For example:"

Seems like I might be able to use that to replace when I use
file_get_conten ts to get the php code to execute?

Thanks,
Jon

Apr 28 '07 #1
25 3130
Jon Slaughter wrote:
Is there any command that essentially executes the code and then
echo's it?
For this specific case you could use eval:

$code = "?><body>blah<? php echo 'Hello'; ?></body>";
eval($code);

Note that the closing tag at the beginning of the eval string is mandatory.
JW
Apr 28 '07 #2

"Janwillem Borleffs" <jw@jwscripts.c omwrote in message
news:46******** *************** @news.euronet.n l...
Jon Slaughter wrote:
>Is there any command that essentially executes the code and then
echo's it?

For this specific case you could use eval:

$code = "?><body>blah<? php echo 'Hello'; ?></body>";
eval($code);

Note that the closing tag at the beginning of the eval string is
mandatory.

Ok. Thats not the specific case I need but maybe it will still work? It is
essentially what I have. That is, I have an html file with some php code in
it similar to the example but just more complex. (actually right now its
just plain html but when I want to add some php stuff I'll need to be able
to have it evaluated).

Thanks,
Jon
Apr 28 '07 #3
On Sat, 28 Apr 2007 22:11:45 GMT, in comp.lang.php "Jon Slaughter"
<Jo***********@ Hotmail.com>
<BE************ ***@newssvr11.n ews.prodigy.net wrote:
>|
| "Janwillem Borleffs" <jw@jwscripts.c omwrote in message
| news:46******** *************** @news.euronet.n l...
| Jon Slaughter wrote:
| >Is there any command that essentially executes the code and then
| >echo's it?
| >
| For this specific case you could use eval:
| >
| $code = "?><body>blah<? php echo 'Hello'; ?></body>";
| eval($code);
| >
| Note that the closing tag at the beginning of the eval string is
| mandatory.
| >
| >
|
| Ok. Thats not the specific case I need but maybe it will still work? It is
| essentially what I have. That is, I have an html file with some php code in
| it similar to the example but just more complex. (actually right now its
| just plain html but when I want to add some php stuff I'll need to be able
| to have it evaluated).
Make sure the file has the extension of php.
---------------------------------------------------------------
jn******@yourpa ntsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Apr 29 '07 #4
Jon Slaughter wrote:
That is, I have an html file with some php code in it similar to the
example but just more complex.
Let me get this straight... you have an HTML+PHP file. You want your
script to open this file, run the PHP code inside and echo the whole thing
out to the client?

include 'file.php';

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Apr 29 '07 #5

"Toby A Inkster" <us**********@t obyinkster.co.u kwrote in message
news:d5******** ****@ophelia.g5 n.co.uk...
Jon Slaughter wrote:
>That is, I have an html file with some php code in it similar to the
example but just more complex.

Let me get this straight... you have an HTML+PHP file. You want your
script to open this file, run the PHP code inside and echo the whole thing
out to the client?

include 'file.php';
You obviously didn't read what I said... Sometimes simple answers are not
the correct ones.
Apr 29 '07 #6
Message-ID: <Uq************ ****@newssvr19. news.prodigy.ne tfrom Jon
Slaughter contained the following:
>include 'file.php';

You obviously didn't read what I said... Sometimes simple answers are not
the correct ones.

The answer was correct. It's the question we are having a problem with.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Apr 29 '07 #7

"Geoff Berrow" <bl******@ckdog .co.ukwrote in message
news:05******** *************** *********@4ax.c om...
Message-ID: <Uq************ ****@newssvr19. news.prodigy.ne tfrom Jon
Slaughter contained the following:
>>include 'file.php';

You obviously didn't read what I said... Sometimes simple answers are not
the correct ones.


The answer was correct. It's the question we are having a problem with.
Thats always the case with you guys. Your always right regardless of the
question. "Whats 2 + 2" -"The milk is made from cheese". "But your
wrong!" -"No, your question is wrong".

Your a dipshit...

Apr 29 '07 #8
Message-ID: <5C************ ****@newssvr23. news.prodigy.ne tfrom Jon
Slaughter contained the following:
>Your a dipshit...
No, that's /you're/ a dipshit.


--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Apr 29 '07 #9
"Jon Slaughter" <Jo***********@ Hotmail.comwrot e in message
news:tP******** ********@newssv r23.news.prodig y.net...
I have some code that loads up some php/html files and does a few things
to
them and ultimately returns an html file with some php code in it. I then
pass that file onto the user by using echo. Of course then the file
doesn't
get seen by the user.
If you have an html file, that is, a file containing html markup with "html"
or "htm" extension it is _not_ parsed by the php engine,, normaly.
Is there any command that essentially executes the code and then echo's
it?
>
Yes, it's called "print" and it can do more complex things than echo will,
it's simlar, but not actualy the same.
It's described
here->http://www.faqts.com/knowledge_base/...l/aid/1/fid/40
something that will take a string like

'<body>blah<?ph p echo 'Hello'; ?></body>' and actually interpret the php
code?
Yes, there is.
-------------------------------------
!DOCTYPE blah blah blah
<html>
<head><title> </title></head>
<p>stuff in this file that contains html markup with a ".php" extension</p>
<p>Other stuff</p>
<?php
echo '<p>Parse this and include it into the html stuff above and
below</p>';
?>
<p>Other stuff in this file that has a ".php" extension and will be output
as html by the php engine.</p>
<?php
echo '<p>Parsed and included as html in the output with the other markup
around it</p>';
?>
<p>More html markup</p>
<?php
include(myFileI DidStuffTooAMom entAgo.inc);
?>
</body>
</html>
------------------------------------fileName.php
>
e.g., doing

echo '<body>blah<?ph p echo 'Hello'; ?></body>';

does me no good caues the php code isn't interpreted.
But would if you wrote it as below and saved the file with a php extension..
<body>blah
<?php
echo 'Hello';
?>
</body>
>
Saving it to a file and then redirecting the user to that file so it will
be
executed seems like a roundabout way and causes more problems.
I would have to agree.
>
essentially I am trying to include php/html files in one another but I
need
to do some parsing on them first. I'd rather not do something like
Parsing is a very generic term and may include opperations that have nothing
to do with html output, or php for that matter.
It can only be assumed that you mean "interprete d by the php engine" but you
seem to indicate something else by the context here.
>

file_get_conten ts($Page)
parse($Page)
save($Page)
include "$Page"
The above could be written into a file with a .php extension as;
---------------------
<?php
$Page = file_get_conten ts('somepath/Page.txt')
function parse(&$Page)
{
//Losts of parsing code here
}
parse($Page);
file_put_conten ts($Page);
?>
----------------------
>
as it seems uncessary to have to write the page to disk just to include
it.
>
I would have to agree. So you might write the above as follows;
---------------------
<?php
$Page = file_get_conten ts('somepath/Page.txt')
function parse(&$Page)
{
//Losts of parsing code
}
parse($Page);
echo $Page;
[Or
print parse($Page);
Or
echo parse($Page);
]
?>
----------------------

I'm not sure that the above is usefull. There seems to be some confusion
about what exactly you are wanting to do.
It may be an inaquacey on my part, or it may be ambiguity on your part ;)
HTH
Vince
Apr 29 '07 #10

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

Similar topics

3
19885
by: Dariusz | last post by:
I have a problem where I need to pass two variables using GET from a form I have, to solve a page selection problem I have. The code is written that if a new visitor arrives at the front page of the site, because the page id is null, PHP loads the default design. But when I execute one of my other pages which has a form on it, because I cannot pass back the id of the page that the form is on (the "submit" GET's the desired page id...
2
3227
by: Tobias Hesselmann | last post by:
Hi folks, i have a problem using a PHP script as a custom handler in Apache. What i wanna do is this: Whenever a .html file is requested by a browser, i want Apache to call a CGI that outputs a header, then the requested file and then a footer. I want to use PHP for this, as i also want to do some template parsing. Well, basically, this can be done using Apache's mod_action module,
9
11233
by: Lauren Quantrell | last post by:
Is there a way to create a text file (such as a Windows Notepad file) by using a trigger on a table? What I want to do is to send a row of information to a table where the table: tblFileData has only one column: txtOutput I want to use the DB front end (MS Access) to send the text string to the SQL backend, then have the SQL Server create a file to a path, such as F:/myfiledate.txt that holds the text in txtOutput, then the trigger...
11
6600
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on where the job is running, the job runs sucessfully, PDF files got generated, everything is good. If I scheduled the job to run at the time that I am not logged into the server, Access is not able to print to the printer. The error is pretty...
16
3497
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record in a hidden field) I wish the user to be able to edit the data in the table, so I have extracted the records into hiddenfield, textareas, dropdown list and checkbox so that they can make changes. I named these elements as arrays and wish to run an...
1
4704
by: balas1 | last post by:
hi i need to execute unix command from browser. but i cant get any output in my browser side.. need to enable anything to execute unix command from browser using php my coding is <?php $output = exec('ls -lart');
221
367707
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application needs to store entire files, the preferred method is to save the file onto the server’s file-system, and store the physical location of the file in your database. This is generally considered to be the easiest and fastest way to store files. ...
1
1601
by: =?Utf-8?B?Sm9obkJhdGVz?= | last post by:
Problem: I need to backup and clear the security event log. I have this working via a vbsscript which I will post below. However while I can use this script manually it is not user friendly and my end users who have to perform the backup and clear chore weekly are the "where is the button" types. I have written a vb.net 2005 gui as a front end that can launch my script and run it ok but the problem is since it is a script running in a...
6
1859
by: BOMEz | last post by:
So i've recently been starting to program PHP in an object oriented way, but I'm running into some difficulties in from a design stand point and from an object oriented stand point: Issue 1: In my class I cannot give visibility to any variable, it simple breaks everything. For example if I do: private $private = 'Private'; I get the error : The error is the same if I use public or protected. I have tried declaring a a private variable in...
0
9377
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.