SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    midnight coder
    Join Date
    Dec 2000
    The flat edge of the world
    0 Post(s)
    0 Thread(s)
    I'm just trying out PHPLib's script. So far I have the following:

    $display = 'news.php';

    include ('template/');

    $t = new Template();


    The $display variable was from a simple if statement.

    Anyway, my site design's on a file call, and I want to put the page news.php in it, but the script above only replace the {content} tag with the words "news.php", how do I get it to display the actual news.php page, not just the name?

  2. #2
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Lawrence, Kansas
    0 Post(s)
    0 Thread(s)
    At the moment the command:
    PHP Code:
    $display 'news.php'
    only sticks the string 'news.php' into the variable. Presumably you want to stick the output of news.php in there exactly as it would appear if you ran the script normally.

    This is actually quite a tricky thing to do. There are very easy ways of reading the contents of a text file into a variable but if you used that technique the variable would contain PHP code, and you want the variable to contain executed code.

    It's possible the eval function may be of use here, but I've never used it myself:

    There are work arounds for grabbing the parsed content of a PHP file, but none of them are particularly elegant. You could use fopen to open the page by calling the full URL (including the http: bit), or you could even use PHP 4's buffers to grab the parsed HTML for news.php from the buffer but both of these solutions over complicate things.

    The optimal solution would be to re-use the code from news.php so that instead of printing HTML directly it saves all the HTML generated to a variable. You could then use that variable with your templates.

    Hope this helps,



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts