Page 1 of 1

php content injection

Posted: Sun Jul 12, 2009 5:13 pm
by wkphilip
i want to be able to inject a module, such as an iframe... but i dont want to go with iframes. is this possible to do?

if so, can some one guide me in the right direction?

like, almost as if i could include a page/.php file

Re: php content injection

Posted: Sun Jul 12, 2009 11:21 pm
by Christopher
wkphilip wrote:like, almost as if i could include a page/.php file
Good guess. You can do:

Code: Select all

include 'mypage.php';
See the manual:

http://us3.php.net/manual/en/function.include.php

Re: php content injection

Posted: Mon Jul 13, 2009 7:42 am
by alex.barylski
Use a template engine like Smarty or the following lightweight implementation:

Code: Select all

 
<?php
 
  class Template{
    function execute($path)
    {
      ob_start();
      include($path);
      $buff = ob_get_contents();
      ob_end_clean();
    }
  }
 
Then you define the template like so:

Code: Select all

<html>  <head>    <title><?php echo $this->title; ?></title>  </head>  <body>    <?php echo $this->content; ?>  </body></html>
And you would use them both like so:

Code: Select all

$template = new Template();
$template->title = 'Use this title pulled from a database or something?';
$template->content = 'Here is the content with <strong>HTML</strong> also pulled from a database or file?';
echo $template->execute('path/to/your/template.php');
HTH

Cheers,
Alex