Forum Moderators: coopster
The template looks like this:
<?php
$templ = '
Regular HTML Here
<?php include 'TestInclude.php';?>
More Regular HTML Here
';
?>
No matter what I try I get a T_string error each time I try to put that include in there like that. Is there some other way I should be doing this?
Thanks!
The problem I see is that you've the include, and all the html, defined as the variable $templ.
I'm not sure what $templ should be, but the include should be placed outside the tic marks, thusly:
<?php
$templ = 'Regular HTML Here More Regular HTML Here ';
include 'TestInclude.php';
?>
Also, you have enclosed the include within the php tags, which is placed inside php tags, and that just won't do.
Note I removed the php tags from the include. Hopefully that will get you going.
<edit>
Looking at your example, this is probably closer to what you are trying to accomplish:
<?php
$templ = 'Regular HTML Here';
$templ .= include ('TestInclude.php');
$templ .= 'More Regular HTML Here ';
?>
I can't say for sure that the include will work like this, if not, bring it back and we'll have another look.
</edit>
<?php
$templ = 'Regular HTML Here ';
$templ .= include ('TestInclude.php');
$templ .= ' More Regular HTML Here';
echo "$templ";
?>
Displays:
Regular HTML Here 1 More Regular HTML Here
if the include file is found, and
Regular HTML Here More Regular HTML Here
if the include file is not found.
The content of the include displays above the echoed output.
(I placed some content in the include so I could observe the results.) Basically, only the status, either 1 or NULL is being returned to the string.
We've almost exceeded my limited knowledge... anyone else?
$filearray=file('/path/to/file.ext'); will put the contents into an array, one line per element
$filestring=file_get_contents('/path/to/file.ext'); will put the contents into a string
You can find out more about each of these functions (as well as other methods, such as using fopen() and fgets()) at the PHP manual at [php.net...]