DanMan101 wrote:Hello-
Here is my situation:
I have an html template file.
template.htm:
Code: Select all
...
<!--begin-->
<title><?php echo $page_title ?></title>
<!--end-->
...
I have a php script that wants to display selected lines from template.htm, such as anything between the begin and end comments.
test.php
Code: Select all
$lines = file('template.htm');
$page_title = "My Page Title";
foreach ($lines as $line) {
... // detect if line within begin and end comments
if ($withinTags) {
echo $line;
}
}
The resulting page will have a page title of "<?php echo $page_title ?>" instead of the desired "My Page Title".
How do I get it to parse the php code within the $line string?
Thanks for the help,
DanMan101
I think I see what your trying to do now...
Basically...use the code you have, but instead of
file() use
include()
Now just use one of PHP's string functions like
explode() to turn the parsed/processed template into an array of lines...
Code: Select all
$arr_of_lines = explode('/n', $contents);
Depending on which system (Windows, *nix, Mac, etc) the seperator string may vary...
For instance on Windows CRLF (10+13 or "/r/n") would be required to break a string into lines...however on Linux I believe it's just "/n"
so...
Code: Select all
$arr_of_lines = explode('/n', $contents);
Should work...
That is if memory serves me correctly
Cheers
