php content injection

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
wkphilip
Forum Newbie
Posts: 1
Joined: Sun Jul 12, 2009 5:09 pm

php content injection

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: php content injection

Post 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
(#10850)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: php content injection

Post 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
Post Reply