SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict mari's Avatar
    Join Date
    Nov 2007
    Location
    London, UK
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question file_get_contents

    hey guys

    i am trying to include a php file. This contains some html and css. These print fine but the php within the file is ignored?

    $template = file_get_contents('template.php');

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you want the php code to be executed, use include

    If you want to capture the output, wrap it in ob_start() and ob_get_clean()

  3. #3
    SitePoint Addict mari's Avatar
    Join Date
    Nov 2007
    Location
    London, UK
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $template = include('template.php');

    can the above code be assigned to the $template variable or is that wrong?

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    That would work.

    See the docs.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Addict mari's Avatar
    Join Date
    Nov 2007
    Location
    London, UK
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried it and it now shows the php...however i noticed another thing, it makes it ignore another bit of code which is

    $page = preg_replace('/##CONTENT##/', $content, $template);

    when i leave it at $template = file_get_contents('template.php'); the preg_replace works but the PHP code doesnt and when i replace file_get_contents with include the PHP in the works but the content in preg replace doesnt show

    is there a way to make them both show

  6. #6
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The way is not to mix two technologies.
    If you want your template to be PHP code, do not place there such things like /##CONTENT##/
    But just substitute it with
    <?php echo $content ?>

  7. #7
    SitePoint Addict mari's Avatar
    Join Date
    Nov 2007
    Location
    London, UK
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Shrapnel_N5 View Post
    The way is not to mix two technologies.
    If you want your template to be PHP code, do not place there such things like /##CONTENT##/
    But just substitute it with
    <?php echo $content ?>
    thanks

  8. #8
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AnthonySterling View Post
    That would work.

    See the docs.
    Are you sure? $template would either include 1, or a value return()d from the included file, but not the contents of that file.


Bookmarks

Posting Permissions

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