Solved

Throwing the content of a file directly to the browser (echo a whole file?)

Posted on 2003-11-19
1
236 Views
Last Modified: 2013-11-18
This should be an easy one:
Which is the most effective way (short code, less server processing) to send a whole file to the web client?
What I want to do is this:
Have 4 files: header.html, body1.html, body2.html,footer.html
What I want is depending on some condition the user gets a page which is header+body1+footer or if not header+body2+footer.
Using include or require in PHP includes a file in the current script, which will force me to have humdreds of "echo"s in each of the 4 files to output the HTML - definitely not praclical.
Probably a way would be to read each line-by-line and echo each read line, but I want to know if there is any intelligent and straightforward solution?
0
Comment
Question by:celeron128
1 Comment
 
LVL 6

Accepted Solution

by:
DoppyNL earned 50 total points
ID: 9777452
you can also include html files....

so you can do this:

---- somefile.html
<html>
<head><title>HEAD!!!</title></head>
<body>
-----


---somepage.php
<?php
include('somefile.html');
print('do some other stuff');
print('</body></html>');
?>
-----


or partial php partial html files is also possible. :)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now