You are here: Re: Parsing a php include (which also contains php code) - or "Reparsing" the php file « PHP Language « IT news, forums, messages
Re: Parsing a php include (which also contains php code) - or "Reparsing" the php file

Posted by J.O. Aho on 06/22/07 15:18

Steven Borrelli wrote:

> When you say the PHP includes have nothing to do with the web server,
> that is somewhat confusing.

The web server won't load the included files, it won't have a clue what has
been included, as this is handled by the PHP parser module.


> If I have my index.php, and I have a call to a php include within
> that, and also another php include within the first include, and all
> the includes have the .php file extension, will everything be parsed
> and appear like it's supposed to?

The extension has nothing to do with if the file will be parsed or not, but of
"security" reasons it's vise to set the php extension to the include files too.

When you include a php script, see to that the PHP code in that file has the
'<?PHP' and '?>' tags, or else the php code will be treated as plain text.

example:

--- file1.inc.php ---
<?PHP
echo "Hello";
?>
--- eof ---


--- file2.inc.php ---
echo "Hello";
--- eof ---


--- index.php ---
<html><head><title>php include test</title></head><body>
First include: <?PHP include 'file1.inc.php'; ?><br>
Second include: <?PHP include 'file2.inc.php'; ?><br>
</body></html>
--- eof ---


If you run this small example you will notice that the output will look like this:

First include: Hello
Second include: echo "Hello";



> In other words, is it possible to make nesting php includes?

Sure you can, there is no problems with that at all and it's justed quite a
lot on the most big projects you can find (see freshmeat.net).


--

//Aho

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация