|
Posted by Jon Slaughter on 04/29/07 12:31
Well, I thought I was clear enough. I think what happens is because I use a
simple example that many here think there must be a simple solution. I give
a simple example only to express the problem as concisely as I can instead
of cluttering it up with things that are irrelevant and, I would assume,
only cause more confusion. Its like a math problem, If there is something
I'm trying to solve but the equation is very complicated and I can reduce
the issue down to a similar but much more simple problem then thats what I
would do. I believe my original explination was simple and explained the
problem but I could be wrong. I have gotten a solution from Janwillem which
probalby will work(haven't tried it yet due to other issues).
If it was simple as using include then I would have done it. Peopl elike
Toby and Geoff have a very simplistic view of things and there problem is
that their ego always ends up showing up.
In any case, again, I have a file that is essentially html code in it. It
has a php extension as all my files do. That is not the issue.
The issue is that I have this file, call it MyFile.php and I want to parse
it to modify some html code or generate some html code based on some
context. If I just use include then I have no way of looking at the file?
If I do
include 'MyFile.php'
Then how am I going to modify what I need to modify? Theres no way to get at
the contents of the file that is loaded do do anything.
For example, what if MyFile.php is
<body>
Hello
<div class="table"></div>
<?php
echo 'hello';
?>
</body>
REMEMBER THIS IS JUST A SIMPLIFIED EXAMPLE. Obviously if this was what I was
really trying to do there would be no need to parse it as I could approach
it differently. (so don't tell me I need to approach it differently because
its actually more complicated and maybe I did things backwards but its too
late at this point)
In any case, now I have a file called AddTable.php that essentially takes
this file and parses it for <div class="table"> and inserts a table inside
that div.
if I simply do
include 'MyFile.php'
then how can I parse it?
if I do
$file = file_get_contents('MyFile.php');
Then I can easily parse the string $file and modify it to add the table.
so after that I now have $file that looks something like
<body>
Hello
<table>
<tr>
<td>Blah
</td>
</tr>
</table>
<?php
echo 'hello';
?>
</body>
and when I want to send it to the client,
echo $file;
it will not interpret the php code and just send it as text to them (so they
get exactly what is above in $file instead of
<body>
Hello
<table>
<tr>
<td>Blah
</td>
</tr>
</table>
hello
</body>
So I need a way to get $file to interpret the php code before I send it.
Janwillem has said eval will do it and from looking in the manual it seems
like it will work. There is also another solution I mentioned in the
original post that looks like it will work. I might have been able to design
the site differently and been able to avoid this issue but I didn't and I'm
not about to start over at this point just because some jack ass(not you)
gets to confused and doesn't understand the problem.
In any case I hope to try eval soon as I think it will be the easiest
solution and do exactly what I need.
Thanks,
Jon
[Back to original message]
|