Re: Static Pages with PHP
| From: | Paul Novitski | Date: | Mon, 20 Nov 2006 05:41:56 +0000 |
| Subject: | Re: Static Pages with PHP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-244857@lists.php.net to get a copy of this message | ||
At 11/19/2006 08:50 PM, John Comerford wrote:
I am new to PHP and I am looking at mixing dynamic and static pages to build my web application. I have a situation where, depending on some parameters I will display a static page from within my PHP code. My question is, is there a 'trick' to doing this or do I just read in the file and echo it out again ?If I understand you correctly, you've got a PHP script that determines whether to download dynamic content or a static page. In the latter case, you have some options: a) You can redirect to the static page. It can have either an .html extension or a .php extension. If all it contains is HTML markup, that's what will be downloaded to the client. http://php.net/header header("Location: http://www.example.com/"); b) You can read the HTML markup from a separate file and echo it to the client. (e.g., file(), get_file_contents()) http://php.net/file_get_contents echo file_get_contents('example.html'); c) You can embed the static HTML markup inside your PHP file and echo it to the client. (e.g., heredoc) http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc echo <<< label <html>...</html> label; I put these three in order of personal preference. I try to separate PHP logic from HTML markup whenever possible, and I can't see why you'd want to embed the HTML in your PHP file when it would be much easier to maintain as a separate file. Reading the HTML with PHP and echoing it to the client is fine but seems like a questionable use of server resources if your goal can be achieved simply by redirecting to the static page. Regards, Paul