Page 1 of 1

how to make php script within a php variable to work?

Posted: Sun Jan 22, 2006 1:02 am
by bloodfire
Considered the following sample php files.

Example File 1 (file1.php) -- some programming script (actually more complicate than this, it is used to retrieve XML codes and displaying them)

Code: Select all

<?
echo "This is a test!";
?>
Example File 2 (index.php) - the running page

Code: Select all

<?
$getinclude = get_include_contents('file1.php');

$body = "<tr><td>".$getinclude."</td></tr>"

include('file3.php');
?>
File 3 (file3.php) --- considered as the template

Code: Select all

<html>
......
The normal HTML opening tags
......
<?php
print $body;
?>
......
The normal HTML closing tags
......
</html>
I couldn't get to display the contents retrieved from file1.php and displaying them in the running page. I could but them into 1 file, which works perfectly, but I wouldn't like to have all the pages to have repeated codes especially the template codes. I think the problem lies in the index.php.

Can some1 help me?

Re: how to make php script within a php variable to work?

Posted: Sun Jan 22, 2006 1:49 am
by stuffradio
bloodfire wrote:

Code: Select all

<?
$getinclude = get_include_contents('file1.php');

$body = "<tr><td>".$getinclude."</td></tr>"

include('file3.php');
?>
File 3 (file3.php) --- considered as the template

Code: Select all

<html>
......
The normal HTML opening tags
......
<?php
print $body;
?>
......
The normal HTML closing tags
......
</html>
Everything You are doing is way too Complicated than it needs to be.

Code: Select all

<?
echo "<tr><td>"This is a test!"</td></tr>";?>
Ok that's fine.

Code: Select all

<?
$getinclude = get_include_contents('file1.php');

$body = "<tr><td>".$getinclude."</td></tr>"

include('file3.php');
?>
It should really be:

Code: Select all

<?
include("file1.php");

include("file3.php");
?>
If you do it like that than it should work fine.