Parse interpret code from file?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Muffinthief
    New Member
    • May 2007
    • 51

    Parse interpret code from file?

    Hey this is an odd question. So I'm designing a website with certain elements repeating. So I put the code for those sections into individual files, then would have php load the html into the page, so if I wanted to change something I would only have to change it in one place. The problem is that some of the parts contain php code, that is echoed into the document as straight text, and not interpreted. Is there a way to have php do multiple passes, or is there a way to find the path to the php executable on a server? ("/usr/bin/php" on *nix I think) Thanks for the help guys!
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Could you provide an example? It's 3am. :)

    Comment

    • Muffinthief
      New Member
      • May 2007
      • 51

      #3
      haha sorry, so in the main file I have:

      Code:
      <?php function writestatic($item) {
      		$path = softrootpath() . '/static-items/'.$item;		
      		$f = fopen($path, 'r');
      		$data = fread($f, filesize($path));
      		echo $data;
      } ?>
      then in static-items/menu I have

      Code:
      <div id="menucontainer">
      	<div id="menunav">
      		<ul>
      		<li><a href="<?php echo rootpath(); ?>/index.php" title="Home" class="current"><span>Home</span></a></li>
      		</ul>
      	</div>
      </div>
      so then back in the main file

      Code:
      <?php writestatic('menu')?>
      so when I try to link to home It tries to take me to "<?php echo rootpath(); ?>/index.php"

      thanks guys!
      Last edited by Muffinthief; Aug 21 '08, 02:13 AM. Reason: forgot code tags

      Comment

      • Muffinthief
        New Member
        • May 2007
        • 51

        #4
        ok wow I'm stupid. Include. Forget this thread.

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Originally posted by Muffinthief
          Forget this thread.
          Forget what thread? (:

          Glad to hear you were able to get it working, though. Good luck with your project!

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Just for the record, this could also have been done with the eval function.
            Although include is better in this case.

            Comment

            Working...