File Contents

Hello guys,

I need something like this:

  1. include php file which dynamically generates HTML
  2. Instead displaying the content I wish to read the file content and process the content

Hello [USER]! Welcome to my web site

I wish to process place holder [USER]

            include ($path); 
            $s = ob_get_contents();

          echo $s; // nothing displayed. Any idea?

Thanks in advance.

Also, if you can provide one good resource for Template caching it would be great!

I remember doing something similar once.

Read the contents of the template file, and store it in variable.

Then, perform a replace to replace a tag with whatever you want (page content for example).

Then I believe there’s a EVAL command, where you pass PHP/HTML to it, and it’ll actually executes the code within it, then finally, you need to echo the output.

If however you’re just putting HTML into the template, then a simple, load the template, str_replace() what you need to, and echo out the contents.


$template = ‘<h1>Welcome to my site</h1><div>{content}</div>’;
$inner_content = ‘<p>Some other text in here</p>’;
echo str_replace(“{content}”,$inner_content,$template);

or, if there is PHP in the $inner_content, something like
echo eval(“?>” . str_replace(“{content}”,$inner_content,$template) . “<?php”);

I have a template file named “Artistlist” and there’s are couple of meta tags which I need to replace with actual. [TITLE] etc

ArtistList queries Data model and fetches the list with full HTML markup but Meta tags needs to be actual ones which must relate to Artist List for example.

include"artlist.php"; << this is printing the content I want the content in a variable as string.

Any ideas?

include "artist.php";


Content Encoding Error

Content encoding error oops!

The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.
* Please contact the website owners to inform them of this problem.


Error was due to:

ob_start("ob_gzhandler"); // error
ob_start(); // << changed to this

Any idea?

can’t you just perform a replace?

$template_html = ‘<title>{meta_title}</title>
<meta name=“description” content=“{meta_description}” />
<meta name=“keywords” content=“{meta_keywords}” />’;

$template_html = str_replace(‘{meta_title}’,$artist[‘title’],$template_html);
$template_html = str_replace(‘{meta_description}’,$artist[‘description’],$template_html);
$template_html = str_replace(‘{meta_keywords}’,$artist[‘keywords’],$template_html);

echo $template_html;

ob_start(“ob_gzhandler”); compresses the output with gzip.
Either the whole page needs to compressed using gzip and the appropriate headers sent, or none of it must be compressed.
In your case you only compressed only part of the page, and that doesn’t work :slight_smile: