Re: Repetetive code question [message #179646 is a reply to message #179644] |
Thu, 15 November 2012 15:36 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma:
|
Senior Member |
|
|
Goran wrote:
> On 15.11.2012 13:26, Dynamo wrote:
>> Not sure if this is the right place to ask this question as it is more
>> an html query than a php one but here goes anyway.
>>
>> I have a large chunk of html code that is used to build an extensive
>> drop down menu. The same code is used on all 30 of my web pages. So I
>> have seperated the code into a txt file called menu.txt and used the
>> following php code to get the file contents:
>> [
>> <?php
>> $mymenu=file_get_contents('menu.txt');
>> echo $mymenu;
>> ?>
>> ]
>> Everthing works fine but is this good practice and is there a better
>> way.
>
> This should be:
>
> <?php readfile('menu.html') ?>
How do you know this is not an example and they want to process the file
contents before writing it to the standard output?
And there appear to be issues with readfile(), enabled output buffering and
large files or slow connections. Not so with file_get_contents();
<http://php.net/readfile>
<http://php.net/file_get_contents>
PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(at)news(dot)demon(dot)co(dot)uk> (2004)
|
|
|