473,320 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 1223
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

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

Similar topics

9
by: franzkowiak | last post by:
Hello, I've read some bytes from a file and just now I can't interpret 4 bytes in this dates like a real value. An extract from my program def l32(c): return ord(c) + (ord(c)<<8) +...
2
by: Peter Kirk | last post by:
Hi there I would like some help with parsing date strings to DateTime structures. I can see that DateTime has Parse and ParseExact methods - but I am not sure what is best for me to use, and...
0
by: Jack Hambabo | last post by:
Hi, I'm searching for a php script that can find out whether the current user (I know _SERVER will give me the name for non-cgi php) has the right to view a specific file. My dream is that I...
2
by: hup | last post by:
One of my Linux (CentOS) server stop interpret php code any more. I did try to compile and installed other version of php, but it's still not working. # cat /tmp/phpinfo.php <? phpinfo() ?>...
29
by: gs | last post by:
let say I have to deal with various date format and I am give format string from one of the following dd/mm/yyyy mm/dd/yyyy dd/mmm/yyyy mmm/dd/yyyy dd/mm/yy mm/dd/yy dd/mmm/yy mmm/dd/yy
5
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
24
by: Gary Hasler | last post by:
I want apache to parse all .html files for php code. Our 'real' web server is rented from ICDsoft ( php 5 on Apache on Linux whatever), and their instruction is to add the following to the...
5
by: goldtech | last post by:
SAX XML Parse Python error message Hi, My first attempt at SAX, but have an error message I need help with. I cite the error message, code, and xml below. Be grateful if anyone can tell me...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.