471,122 Members | 1,001 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,122 software developers and data experts.

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!
Aug 21 '08 #1
5 1172
Markus
6,050 Expert 4TB
Could you provide an example? It's 3am. :)
Aug 21 '08 #2
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
ok wow I'm stupid. Include. Forget this thread.
Aug 21 '08 #4
pbmods
5,821 Expert 4TB
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
Atli
5,058 Expert 4TB
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.

Similar topics

9 posts views Thread by franzkowiak | last post: by
2 posts views Thread by Peter Kirk | last post: by
reply views Thread by Jack Hambabo | last post: by
2 posts views Thread by hup | last post: by
29 posts views Thread by gs | last post: by
AdrianH
5 posts views Thread by AdrianH | last post: by
AdrianH
1 post views Thread by AdrianH | last post: by
24 posts views Thread by Gary Hasler | last post: by
5 posts views Thread by goldtech | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.