473,696 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why does include file text need to be bracketed by <?php> ... <?>

Since the include function is called from within a PHP script, why
does the included file have to identify itself as a PHP again by
enclosing its code in <?php... <?>

One would assume that the PHP interpreter works like any other, that
is, it first expands all the include files, and then parses the
resulting text. Can anyone help with an explanation?

Thanks,
M. McDonnell

May 28 '07 #1
14 3145

"Michael" <Mi************ ***@yahoo.comwr ote in message
news:11******** **************@ z28g2000prd.goo glegroups.com.. .
Since the include function is called from within a PHP script, why
does the included file have to identify itself as a PHP again by
enclosing its code in <?php... <?>

One would assume that the PHP interpreter works like any other, that
is, it first expands all the include files, and then parses the
resulting text. Can anyone help with an explanation?
Because a php can contain other text such as html... the parser is only
signaled to work on the block that is inside a the php tag...

you ever wonder why <? php ?looks like an html tag? cause it is!
May 28 '07 #2
On May 28, 6:03 pm, Michael <MichaelDMcDonn ...@yahoo.comwr ote:
Since the include function is called from within a PHP script, why
does the included file have to identify itself as a PHP again by
enclosing its code in <?php... <?>

One would assume that the PHP interpreter works like any other, that
is, it first expands all the include files, and then parses the
resulting text. Can anyone help with an explanation?

Thanks,
M. McDonnell
It's not supposed to be bracketed by <?phpand <?>, but by <?php and ?
>. That's not necessary, though. You have to put those symbols into
your require-d file if you want it to be understood like php code, but
if you don't, it will be understood as raw output. Just like any other
php file:
<?php
if ( $x ) {
?>
some output here
some output here
some output here
<?php
} else {
?>
some other output here
some other output here
some other output here
<?php

May 28 '07 #3
On May 28, 6:09 pm, "Jon Slaughter" <Jon_Slaugh...@ Hotmail.comwrot e:
"Michael" <MichaelDMcDonn ...@yahoo.comwr ote in message

news:11******** **************@ z28g2000prd.goo glegroups.com.. .
Since the include function is called from within a PHP script, why
does the included file have to identify itself as a PHP again by
enclosing its code in <?php... <?>
One would assume that the PHP interpreter works like any other, that
is, it first expands all the include files, and then parses the
resulting text. Can anyone help with an explanation?
It's not supposed to be bracketed by <?phpand <?>, but by <?php
and ?
>. That's not necessary, though. You have to put those symbols into
your require-d file if you want it to be understood like php code, but
if you don't, it will be understood as raw output. Just like any other
php file:
<?php
if ( $x ) {
?>
some output here
some output here
some output here
<?php
} else {
?>
some other output here
some other output here
some other output here
<?php
}
?>

As for the require-d file, the same counts - if you didn't put <?php
and ?surrounding the contents of the file, they would be understood
as ordinary output, not php code (which, of course, can be exactly
what we wanted).
>
Because a php can contain other text such as html... the parser is only
signaled to work on the block that is inside a the php tag...

you ever wonder why <? php ?looks like an html tag? cause it is!
I wouldn't go that far to say <?php and ?are html tags, although
they do resemble them having lt and gt chars. Actually, the <? and ?>
are part of xml processing instruction declaration syntax, so when we
say "<?php" we say "give the following contents to php", and when we
say "?>", we actually say "those contents end here". So, php code is
actually organized as xml document, and html out of <?php ?>
instructions perfectly fits in that concept, being itself a subset of
xml, although older than xml.

May 28 '07 #4
On May 28, 9:24 am, Darko <darko.maksimo. ..@gmail.comwro te:
On May 28, 6:09 pm, "Jon Slaughter" <Jon_Slaugh...@ Hotmail.comwrot e:"Michael" <MichaelDMcDonn ...@yahoo.comwr ote in message
news:11******** **************@ z28g2000prd.goo glegroups.com.. .
Since the include function is called from within a PHP script, why
does the included file have to identify itself as a PHP again by
enclosing its code in <?php... <?>
One would assume that the PHP interpreter works like any other, that
is, it first expands all the include files, and then parses the
resulting text. Can anyone help with an explanation?

It's not supposed to be bracketed by <?phpand <?>, but by <?php
and ?
. That's not necessary, though. You have to put those symbols into

your require-d file if you want it to be understood like php code, but
if you don't, it will be understood as raw output. Just like any other
php file:
<?php
if ( $x ) {
?>
some output here
some output here
some output here
<?php
} else {
?>
some other output here
some other output here
some other output here
<?php
}
?>

As for the require-d file, the same counts - if you didn't put <?php
and ?surrounding the contents of the file, they would be understood
as ordinary output, not php code (which, of course, can be exactly
what we wanted).
Because a php can contain other text such as html... the parser is only
signaled to work on the block that is inside a the php tag...
you ever wonder why <? php ?looks like an html tag? cause it is!

I wouldn't go that far to say <?php and ?are html tags, although
they do resemble them having lt and gt chars. Actually, the <? and ?>
are part of xml processing instruction declaration syntax, so when we
say "<?php" we say "give the following contents to php", and when we
say "?>", we actually say "those contents end here". So, php code is
actually organized as xml document, and html out of <?php ?>
instructions perfectly fits in that concept, being itself a subset of
xml, although older than xml.
=============== ======
I guess I'm still missing the point. Once the browser interpreter sees
the <?php, it assumes that all text to follow is php code until the
terminating token ?is seen. Now if the include function is called
within the <?php ... ?>, the interpreter still assumes that any text
it sees is PHP. So again, I don't understand why the include text
needs to bracket its code in <?php ...?>. What am I missing here?
Thanks, MDM.

May 28 '07 #5

"Michael" <Mi************ ***@yahoo.comwr ote in message
news:11******** *************@x 35g2000prf.goog legroups.com...
On May 28, 9:24 am, Darko <darko.maksimo. ..@gmail.comwro te:
>On May 28, 6:09 pm, "Jon Slaughter" <Jon_Slaugh...@ Hotmail.comwrot e:>
"Michael" <MichaelDMcDonn ...@yahoo.comwr ote in message
>news:11******* *************** @z28g2000prd.go oglegroups.com. ..
Since the include function is called from within a PHP script, why
does the included file have to identify itself as a PHP again by
enclosing its code in <?php... <?>
One would assume that the PHP interpreter works like any other, that
is, it first expands all the include files, and then parses the
resulting text. Can anyone help with an explanation?

It's not supposed to be bracketed by <?phpand <?>, but by <?php
and ?
>. That's not necessary, though. You have to put those symbols into

your require-d file if you want it to be understood like php code, but
if you don't, it will be understood as raw output. Just like any other
php file:
<?php
if ( $x ) {
?>
some output here
some output here
some output here
<?php
} else {
?>
some other output here
some other output here
some other output here
<?php
}
?>

As for the require-d file, the same counts - if you didn't put <?php
and ?surrounding the contents of the file, they would be understood
as ordinary output, not php code (which, of course, can be exactly
what we wanted).
Because a php can contain other text such as html... the parser is only
signaled to work on the block that is inside a the php tag...
you ever wonder why <? php ?looks like an html tag? cause it is!

I wouldn't go that far to say <?php and ?are html tags, although
they do resemble them having lt and gt chars. Actually, the <? and ?>
are part of xml processing instruction declaration syntax, so when we
say "<?php" we say "give the following contents to php", and when we
say "?>", we actually say "those contents end here". So, php code is
actually organized as xml document, and html out of <?php ?>
instructions perfectly fits in that concept, being itself a subset of
xml, although older than xml.

=============== ======
I guess I'm still missing the point. Once the browser interpreter sees
the <?php, it assumes that all text to follow is php code until the
terminating token ?is seen. Now if the include function is called
within the <?php ... ?>, the interpreter still assumes that any text
it sees is PHP. So again, I don't understand why the include text
needs to bracket its code in <?php ...?>. What am I missing here?
Thanks, MDM.
Thats your problem... php has nothing to do with the browser. Its a server
side scripting language and independent of the client.
May 28 '07 #6
On May 28, 10:05 am, "Jon Slaughter" <Jon_Slaugh...@ Hotmail.com>
wrote:
"Michael" <MichaelDMcDonn ...@yahoo.comwr ote in message

news:11******** *************@x 35g2000prf.goog legroups.com...


On May 28, 9:24 am, Darko <darko.maksimo. ..@gmail.comwro te:
On May 28, 6:09 pm, "Jon Slaughter" <Jon_Slaugh...@ Hotmail.comwrot e:>
"Michael" <MichaelDMcDonn ...@yahoo.comwr ote in message
news:11******** **************@ z28g2000prd.goo glegroups.com.. .
Since the include function is called from within a PHP script, why
does the included file have to identify itself as a PHP again by
enclosing its code in <?php... <?>
One would assume that the PHP interpreter works like any other, that
is, it first expands all the include files, and then parses the
resulting text. Can anyone help with an explanation?
It's not supposed to be bracketed by <?phpand <?>, but by <?php
and ?
. That's not necessary, though. You have to put those symbols into
your require-d file if you want it to be understood like php code, but
if you don't, it will be understood as raw output. Just like any other
php file:
<?php
if ( $x ) {
?>
some output here
some output here
some output here
<?php
} else {
?>
some other output here
some other output here
some other output here
<?php
}
?>
As for the require-d file, the same counts - if you didn't put <?php
and ?surrounding the contents of the file, they would be understood
as ordinary output, not php code (which, of course, can be exactly
what we wanted).
Because a php can contain other text such as html... the parser is only
signaled to work on the block that is inside a the php tag...
you ever wonder why <? php ?looks like an html tag? cause it is!
I wouldn't go that far to say <?php and ?are html tags, although
they do resemble them having lt and gt chars. Actually, the <? and ?>
are part of xml processing instruction declaration syntax, so when we
say "<?php" we say "give the following contents to php", and when we
say "?>", we actually say "those contents end here". So, php code is
actually organized as xml document, and html out of <?php ?>
instructions perfectly fits in that concept, being itself a subset of
xml, although older than xml.
=============== ======
I guess I'm still missing the point. Once the browser interpreter sees
the <?php, it assumes that all text to follow is php code until the
terminating token ?is seen. Now if the include function is called
within the <?php ... ?>, the interpreter still assumes that any text
it sees is PHP. So again, I don't understand why the include text
needs to bracket its code in <?php ...?>. What am I missing here?
Thanks, MDM.

Thats your problem... php has nothing to do with the browser. Its a server
side scripting language and independent of the client.- Hide quoted text -

- Show quoted text -
=============== ==============
Yes, the text "browser interpreter" should replaced by "interprete r".
In any case, it would seem that the question is still valid. Any
comments would be appreciated.
MDM

May 28 '07 #7
On May 28, 12:45 pm, Michael <MichaelDMcDonn ...@yahoo.comwr ote:
=============== ==============
Yes, the text "browser interpreter" should replaced by "interprete r".
In any case, it would seem that the question is still valid. Any
comments would be appreciated.
MDM
I think I see what you're getting at. If you include a file, you still
need parser instructions for the contents of the included file, since
the include file can have processor directives just the same as the
including script does. To wit:

<code file="index.php ">
<?php
include 'html-header.inc.php' ;
include 'main.inc.php';
include 'html-footer.inc.php' ;
?>
</code>

<code file="html-header.inc.php" >
<html>
<head><title><? php echo COMPANY_NAME; ?></title></head>
<body>
<?php include 'company-header.inc.php' ; ?>
</code>

<code file="main.inc. php">
<?php
$inc = '/LIB/section-'.$_GET['section'].'inc.php';
include $inc;
?>
</code>

<code file="html-footer.inc.php" >
<?php include 'company-footer.inc.php' ; ?>
</body>
</html>
</code>

So as you see, you have to have <?php ?tags on included content, as
that included content may still contain a mix of processor directives
and hard-coded data (like html).

Incidentally, you really only need <?php if a page is all php; the
parser will close the file and auto-insert a ?to finish. However, I
generally this to be bad practice and always insert it anyways.

May 28 '07 #8
Michael wrote:
Since the include function is called from within a PHP script, why
does the included file have to identify itself as a PHP again by
enclosing its code in <?php... <?>

One would assume that the PHP interpreter works like any other, that
is, it first expands all the include files, and then parses the
resulting text. Can anyone help with an explanation?
Unlike, say, C preprocessor instructions or java's imports, php
include() is executed when your script runs, not when it compiles. When
interpreter encounters an "include", it reads the given file and
evaluates its context as php code. "include" is just a confusing name,
"included" files are actually not "embedded" in main file.
--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
May 28 '07 #9
On May 28, 10:05 am, "Jon Slaughter" <Jon_Slaugh...@ Hotmail.com>
wrote:
"Michael" <MichaelDMcDonn ...@yahoo.comwr ote in message

news:11******** *************@x 35g2000prf.goog legroups.com...


On May 28, 9:24 am, Darko <darko.maksimo. ..@gmail.comwro te:
On May 28, 6:09 pm, "Jon Slaughter" <Jon_Slaugh...@ Hotmail.comwrot e:>
"Michael" <MichaelDMcDonn ...@yahoo.comwr ote in message
news:11******** **************@ z28g2000prd.goo glegroups.com.. .
Since the include function is called from within a PHP script, why
does the included file have to identify itself as a PHP again by
enclosing its code in <?php... <?>
One would assume that the PHP interpreter works like any other, that
is, it first expands all the include files, and then parses the
resulting text. Can anyone help with an explanation?
It's not supposed to be bracketed by <?phpand <?>, but by <?php
and ?
. That's not necessary, though. You have to put those symbols into
your require-d file if you want it to be understood like php code, but
if you don't, it will be understood as raw output. Just like any other
php file:
<?php
if ( $x ) {
?>
some output here
some output here
some output here
<?php
} else {
?>
some other output here
some other output here
some other output here
<?php
}
?>
As for the require-d file, the same counts - if you didn't put <?php
and ?surrounding the contents of the file, they would be understood
as ordinary output, not php code (which, of course, can be exactly
what we wanted).
Because a php can contain other text such as html... the parser is only
signaled to work on the block that is inside a the php tag...
you ever wonder why <? php ?looks like an html tag? cause it is!
I wouldn't go that far to say <?php and ?are html tags, although
they do resemble them having lt and gt chars. Actually, the <? and ?>
are part of xml processing instruction declaration syntax, so when we
say "<?php" we say "give the following contents to php", and when we
say "?>", we actually say "those contents end here". So, php code is
actually organized as xml document, and html out of <?php ?>
instructions perfectly fits in that concept, being itself a subset of
xml, although older than xml.
=============== ======
I guess I'm still missing the point. Once the browser interpreter sees
the <?php, it assumes that all text to follow is php code until the
terminating token ?is seen. Now if the include function is called
within the <?php ... ?>, the interpreter still assumes that any text
it sees is PHP. So again, I don't understand why the include text
needs to bracket its code in <?php ...?>. What am I missing here?
Thanks, MDM.

Thats your problem... php has nothing to do with the browser. Its a server
side scripting language and independent of the client.- Hide quoted text -

- Show quoted text -
=============== ==============
Yes, the text "browser interpreter" should replaced by "interprete r".
In any case, it would seem that the question is still valid. Any
comments would be appreciated.
MDM

May 28 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1753
by: Bil Click | last post by:
I am coding classic ASP pages in Visual Studio .Net 2003. I have a file called counties_option.asp that just has a list of options: <OPTION VALUE="030">ANSON</OPTION> <OPTION VALUE="040">ASHE</OPTION> etc... I then call this as an include file in several places in a file called page1.asp like this:
3
3351
by: Adam | last post by:
Hi All, Is it possible to use includes dynamically in html. Hopefully the following example will give an idea what I am rying to do. Thanks in advance Adam <script language="javascript">
1
1630
by: RWC | last post by:
Hey Folks! I'm having trouble with an asp page. First off, I'm new to the html / asp world, but not to software development. I'd like to minimize or "normalize" the site, so I'm trying to use one menu page and include it into any page that needs the menu. The problem is, I include the header.asp page, include the menu.asp page, but when I write the body of the page, it sticks the text underneath the side menu. I'd like the text to...
0
1507
by: sharpener | last post by:
I'm new to C# and to newsgroups, so please bear with a possibly foolish query. I'll try to be sensible. The results of /// <summary> ... </summary> etc. appear immediately in the Object Browser, as advertised. But when I try to get the same result with /// <include> ..., no joy. Having spent the better part of 2 days in a textbook-help-and-msdn search, I'm stumped, so I've isolated the problem in a solution consisting of nothing...
2
3006
by: Susan Baker | last post by:
Hi, I am (trying) to compile some code I downloaded from the internet. The sources contain references to header files - using the form : #include <pathname/file> If I change the form to this: #include "pathname/file"
2
2062
by: Nicky | last post by:
hi, all I know we can do this by some jscript. But is there a way to do it in asp.net c# code? In our project, users could sumit a piece of html code and I need to remove all html tag out. What's the better way to do this? Thanks and have a wonderful holiday!
4
9077
by: SammyBar | last post by:
Hi all, I wonder is it possible to upload the content of an <imgfield to a server. The content of the <imgwas downloaded from a web site different from the one it should be uploaded. The image file should not be saved locally before uploading. It should not be visible any <input type=file on the form. How can it be done? I'm working on a project where client javascript requests an image server to generate dynamic images. The client...
4
2132
by: saneman | last post by:
I have a folder 'app' containing a file 'main.cpp' and a subfolder 'types' (containing various header files). In main.cpp some header files from the subdir 'types' are included like: 1) #include<types/vector.h> #include<types/matrix.h> But I have to change them to
6
5460
by: Bernd Gaertner | last post by:
Dear experts, according to the standard, manipulators like noskipws are declared in the header ios (). But when I look at code that is around, I usually see #include<iomanipbeing used. What is the correct include, and why? Thanks in advance for your time! Best regards,
0
8666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8597
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9145
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8880
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4356
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4611
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2319
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.