Re: Repetetive code question [message #179643 is a reply to message #179634] |
Thu, 15 November 2012 15:21 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma:
|
Senior Member |
|
|
Shake wrote:
> El 15/11/2012 13:26, Dynamo escribió:
>> 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.
>
> if the content of 'menu.txt' is HTML... the filename should be
> 'menu.html'.
And the variable is superfluous (except perhaps for debugging):
<?php
echo file_get_contents('menu.txt');
?>
> What you are doing is an include... you can do this way:
>
> <?
> include('menu.txt');
> ?>
That is not equivalent to the above, because with `include' (or
`include_once', `require', or `require_once') the content of menu.txt will
be parsed (searched for <?php … ?> sections which will then be executed).
[I had stumbled over that difference while writing a code compactor for
ECMAScript-based scripts and Cascading Style-Sheets. It turned out that
some of the stylesheets contained `<?' verbatim intentionally (property
values were generated by PHP), and one test ECMAScript-based script
contained it by accident in a regular expression. Because the compactor
(PointedEars' Resource Builder) had to be able to process those resources
even with short_open_tag=1, the regular expression in the ECMAScript-based
script had to be split up. See
< http://PointedEars.de/websvn/filedetails.php?repname=JSX&path=%2Ftrunk% 2Fbuilder.php>
for details.]
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
|
|
|