Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP - Loading PHP style HTML within a file. 1

Status
Not open for further replies.

AndrewTC

Programmer
Jun 10, 2003
5
0
0
AU
Hello there.

I'm trying to write a script that will open a page (full contents of a html page) within a php script. The point of this is to make a php code that will display menu items to create a "frameless" version of a site. I started off using just a simple open file, while (!eof) print out each line of data. Works fine around javascript and html in page (printing it out as a new web page).

Ok, the problem that I'm having is that it doesn't seem to be able to handle a page if it contains php scripts within it. It just seems to print out the php code as plain text. I don't really want to use .inc files either for storing the php code, so I'm not too sure how to work around this. Can't use frames for this either, as that would sort of defeat the whole point.

Cheers.

-Andrew
 
Ok, I'm going to chuck a load of ideas in

Does your host have support for php? did you put '<?php' at the start of your code? Did you somehow get your code in an echo command?
 
Ah, sorry, maybe I wasn't too clear with the origional post.

The host does support PHP, all PHP scripts work fine, all that stuff. What I'm trying to do is a very specific implementation of a PHP program. Something that reads through a file, and adds a few things as appropriate, and displays the modified version. This is NOT writing to the file itself, though. All data needs to be kept in variables. When the appropriate pieces have been added, all the lines are displayed (and should come out in HTML style format).

All this works fine when I try to apply it to straight HTML files. It can read, identify, and display the output in HTML no problems at all.

The problem is, I'm trying to get it to do the same for PHP style html files. The files do work as PHP files, but when I print them out, it will just display the PHP code as plain text.

Looking at the source code of the pages generated, it does seem to be processing and outputting all lines, it's just recognizing it as PHP code when it's all displayed, it's rather thinking of it as all HTML or plaintext code (Ie. Ignoring that <? and ?> signify execute through PHP compiler, but still printing out the code itself).


Ok, because it could be of the things I'm also using for this, I'll mention them.

Currenlty running on an Apache server (Ver. 2.0.46) and using Php version 4.3.2
 
the PHP <??> will not work if u read a file that has php tags, this is beacuse anything read by a file object is treated as string/character and not executed....

the other way is to include the file.. hold all html content in a string variable and echo that variable...

Known is handfull, Unknown is worldfull
 
AndrewTC
I have done something like what you are describing.

I tried opening the file, finding the code I needed, then using PHP's eval() function ( on that code. I found that to be clunky, though, and not well-performing.

My eventual solution was what vbkris seems to be suggesting. I moved all of the &quot;guts&quot; of all my PHP code to separate files, then invoke the code in them through judicious use of include() statements. That way, I can have one code base (the included files) available in multiple formats or templates.

Want the best answers? Ask the best questions: TANSTAAFL!
 
I have been working with templates from the very beginning of my PHP coding.
It keeps a clean separation between code and design. The HTML templates have blocks and variable placeholders that are parsed when processed by the PHP code.
The code is clean, there is just functionality, no layout. The design can be changed at any time without having to disturb the code. In conjunction with CSS attributes that the code can produces (and the HTML links it to a class/style definition) I find this to be the most versatile and clean solution. The only caveat might be to check the processing load/time.

sleipnir's modular concept IMO is also the most versatile and economic coding practice. Only load conditionally what's needed and share modules that are so abstract that they can be used for many applications.
 
Yeah, I was trying to see if I could get around this without removing the actual parts of the PHP into include statements and then implementing them it certain files are being read. But, yeah, not much else seems to be adequately working, so it looks like the way I'm going to have to go. Just thought there may have been some way to get the page (with PHP content) translated to HTML format, and then perform operations on this.

Thanks for your help on this one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top