By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

Parse interpret code from file?

P: 51
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!
Aug 21 '08 #1
Share this Question
Share on Google+
5 Replies

Expert 5K+
P: 6,050
Could you provide an example? It's 3am. :)
Aug 21 '08 #2

P: 51
haha sorry, so in the main file I have:

Expand|Select|Wrap|Line Numbers
  1. <?php function writestatic($item) {
  2.         $path = softrootpath() . '/static-items/'.$item;        
  3.         $f = fopen($path, 'r');
  4.         $data = fread($f, filesize($path));
  5.         echo $data;
  6. } ?>
then in static-items/menu I have

Expand|Select|Wrap|Line Numbers
  1. <div id="menucontainer">
  2.     <div id="menunav">
  3.         <ul>
  4.         <li><a href="<?php echo rootpath(); ?>/index.php" title="Home" class="current"><span>Home</span></a></li>
  5.         </ul>
  6.     </div>
  7. </div>
so then back in the main file

Expand|Select|Wrap|Line Numbers
  1. <?php writestatic('menu')?>
so when I try to link to home It tries to take me to "<?php echo rootpath(); ?>/index.php"

thanks guys!
Aug 21 '08 #3

P: 51
ok wow I'm stupid. Include. Forget this thread.
Aug 21 '08 #4

Expert 5K+
P: 5,821
Forget this thread.
Forget what thread? (:

Glad to hear you were able to get it working, though. Good luck with your project!
Aug 21 '08 #5

Expert 5K+
P: 5,058
Just for the record, this could also have been done with the eval function.
Although include is better in this case.
Aug 21 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.