You are here: Re: using echo but need something to execute php code « PHP Programming Language « IT news, forums, messages
Re: using echo but need something to execute php code

Posted by Vince Morgan on 04/29/07 11:34

"Jon Slaughter" <Jon_Slaughter@Hotmail.com> wrote in message
news:tPOYh.1739$tp5.630@newssvr23.news.prodigy.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/view.phtml/aid/1/fid/40

> something that will take a string like
>
> '<body>blah<?php 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(myFileIDidStuffTooAMomentAgo.inc);
?>
</body>
</html>
------------------------------------fileName.php
>
> e.g., doing
>
> echo '<body>blah<?php 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 "interpreted by the php engine" but you
seem to indicate something else by the context here.

>
>
> file_get_contents($Page)
> parse($Page)
> save($Page)
> include "$Page"
>
The above could be written into a file with a .php extension as;
---------------------
<?php
$Page = file_get_contents('somepath/Page.txt')
function parse(&$Page)
{
//Losts of parsing code here
}
parse($Page);
file_put_contents($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_contents('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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация