By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,225 Members | 2,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,225 IT Pros & Developers. It's quick & easy.

A very annoying require() -and include()- problem.

P: n/a

[I'm working on PHP version 4.3.4 (which may be of importance, I don't
know). It's the vanilla precompiled www.entropy.ch release for Mac OS
X.]

Hello,

My issue is the following: to promote consistency on a site I'm
building, I decided to go for a php scheme where some recurring
elements (navigation, mostly) are written in a file of their own, which
would then get called from each file needing it by the function
require(). The following example may make this clear (the HTML is
clipped somewhat, but is W3C compliant in full...):

Suppose this is the main file, text.php
<?php require('./lib/head_1.php'); ?>
<TITLE>text</TITLE>
<?php require('./lib/head_2.php'); ?>
the actual body text, html formatted, would go here.
<?php require './lib/foot.php'; ?>
Then, head_1.php would look like:
<?php $nav_basis = "http://localhost/~username/; ?> // will
change once the site is done and is uploaded to the actual server, of
course.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<LINK rel="icon" href="<?=$nav_basis?>favicon.ico"
type="image/x-icon">
<LINK rel="shortcut icon" href="<?=$nav_basis?>favicon.ico"
type="image/x-icon">
<LINK rel="stylesheet" href="<?=$nav_basis?>lib/zaan.css"
type="text/css">
and head_2.php would look like:

</HEAD>
<BODY>
<div>

etcetera, in short: navigational elements with css formatting.

The main point is the variable $nav_basis, which is needed because not
all my files are in the same directory, and I would really would like
to have one file with standard stuff that works throughout the site as
it should. You might suggest using the <BASE> tag in html, but that is
no good: many files on the site are older and large html files with
ample relative crossreferences, which will irrevocably get broken by
such a tag, not to mention get a lot more confusing during future
updates.

My problem now is that Apache, or its PHP module won't properly parse
the PHP that I require(). I do not understand this. The PHP manual
seems to imply that PHP code in an require()ed file will be executed if
tagged properly, but I am having no luck.
As a result, the source file sent to my browser (by Apache, mind you,
not the local filesystem) contains the two head_x.php files as clear
text, showing <?php tags and everything as they are in the source file,
and nothing executed, obviously.
PHP code that I'd write in the main file (text.php) would get executed,
however.
include() shows the same behaviour.

I wonder what the problem is here. Is it my installation of PHP that is
faulty, is it something that I forgot, is it something else?

Can anybody help?

Thanks in advance,
Zaan
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a

"Zaan" <removethis_zaan@removethis_gmx.net> wrote in message
news:300120041643149487%removethis_zaan@removethis _gmx.net...
<?php $nav_basis = "http://localhost/~username/; ?>


Is the closing double quote in the original code missing as well?
Gerard van Wilgen
--
www.majstro.com (On-line translation dictionary / Enreta tradukvortaro)
www.travlang.com/Ergane (Free translation dictionary for Windows / Senpaga
tradukvortaro por Windows)

Jul 17 '05 #2

P: n/a
In article <bv**********@reader11.wxs.nl>, Gerard van Wilgen
<gv********@planet.nl> wrote:
"Zaan" <removethis_zaan@removethis_gmx.net> wrote in message
news:300120041643149487%removethis_zaan@removethis _gmx.net...

<?php $nav_basis = "http://localhost/~username/; ?>


Is the closing double quote in the original code missing as well?
Gerard van Wilgen


No, it is not missing in the original. I must have falsely edited it
out here.

Zaan
Jul 17 '05 #3

P: n/a
The text editor saved your .php file as Unicode?

Uzytkownik "Zaan" <removethis_zaan@removethis_gmx.net> napisal w wiadomosci
news:300120041643149487%removethis_zaan@removethis _gmx.net...

[I'm working on PHP version 4.3.4 (which may be of importance, I don't
know). It's the vanilla precompiled www.entropy.ch release for Mac OS
X.]

Hello,

My issue is the following: to promote consistency on a site I'm
building, I decided to go for a php scheme where some recurring
elements (navigation, mostly) are written in a file of their own, which
would then get called from each file needing it by the function
require(). The following example may make this clear (the HTML is
clipped somewhat, but is W3C compliant in full...):

Suppose this is the main file, text.php
<?php require('./lib/head_1.php'); ?>
<TITLE>text</TITLE>
<?php require('./lib/head_2.php'); ?>
the actual body text, html formatted, would go here.
<?php require './lib/foot.php'; ?>
Then, head_1.php would look like:
<?php $nav_basis = "http://localhost/~username/; ?> // will
change once the site is done and is uploaded to the actual server, of
course.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<LINK rel="icon" href="<?=$nav_basis?>favicon.ico"
type="image/x-icon">
<LINK rel="shortcut icon" href="<?=$nav_basis?>favicon.ico"
type="image/x-icon">
<LINK rel="stylesheet" href="<?=$nav_basis?>lib/zaan.css"
type="text/css">
and head_2.php would look like:

</HEAD>
<BODY>
<div>

etcetera, in short: navigational elements with css formatting.

The main point is the variable $nav_basis, which is needed because not
all my files are in the same directory, and I would really would like
to have one file with standard stuff that works throughout the site as
it should. You might suggest using the <BASE> tag in html, but that is
no good: many files on the site are older and large html files with
ample relative crossreferences, which will irrevocably get broken by
such a tag, not to mention get a lot more confusing during future
updates.

My problem now is that Apache, or its PHP module won't properly parse
the PHP that I require(). I do not understand this. The PHP manual
seems to imply that PHP code in an require()ed file will be executed if
tagged properly, but I am having no luck.
As a result, the source file sent to my browser (by Apache, mind you,
not the local filesystem) contains the two head_x.php files as clear
text, showing <?php tags and everything as they are in the source file,
and nothing executed, obviously.
PHP code that I'd write in the main file (text.php) would get executed,
however.
include() shows the same behaviour.

I wonder what the problem is here. Is it my installation of PHP that is
faulty, is it something that I forgot, is it something else?

Can anybody help?

Thanks in advance,
Zaan

Jul 17 '05 #4

P: n/a
Zaan <removethis_zaan_andthistoo@removethis_gmx.net_and thistoo> wrote in message news:<310120040126327571%removethis_zaan_andthisto o@removethis_gmx.net_andthistoo>...
In article <bv**********@reader11.wxs.nl>, Gerard van Wilgen
<gv********@planet.nl> wrote:
"Zaan" <removethis_zaan@removethis_gmx.net> wrote in message
news:300120041643149487%removethis_zaan@removethis _gmx.net...
<?php $nav_basis = "http://localhost/~username/; ?>


Is the closing double quote in the original code missing as well?
Gerard van Wilgen


No, it is not missing in the original. I must have falsely edited it
out here.

Zaan


Check the HTML Source you are getting in browser, when you execute the script.
Are you getting the PHP source code or the output?
I guess the problem is not in *require* or *include* but some wrong pathing.

All required & included files with proper tags are parsed properly by PHP engine.

--
Hope it will help,
Rahul Anand
Jul 17 '05 #5

P: n/a
In article <Hq********************@comcast.com>, Chung Leong
<ch***********@hotmail.com> wrote:
The text editor saved your .php file as Unicode?
It was. Disabling 'Encode as Unicode' solved the problem. A very good
suggestion! Thanks a lot for that. Do you happen to know why this
problem occured?

Zaan


Uzytkownik "Zaan" <removethis_zaan@removethis_gmx.net> napisal w wiadomosci
news:300120041643149487%removethis_zaan@removethis _gmx.net...

[I'm working on PHP version 4.3.4 (which may be of importance, I don't
know). It's the vanilla precompiled www.entropy.ch release for Mac OS
X.]

Hello,

My issue is the following: to promote consistency on a site I'm
building, I decided to go for a php scheme where some recurring
elements (navigation, mostly) are written in a file of their own, which
would then get called from each file needing it by the function
require(). The following example may make this clear (the HTML is
clipped somewhat, but is W3C compliant in full...):

Suppose this is the main file, text.php
<?php require('./lib/head_1.php'); ?>
<TITLE>text</TITLE>
<?php require('./lib/head_2.php'); ?>
the actual body text, html formatted, would go here.
<?php require './lib/foot.php'; ?>
Then, head_1.php would look like:
<?php $nav_basis = "http://localhost/~username/; ?> // will
change once the site is done and is uploaded to the actual server, of
course.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<LINK rel="icon" href="<?=$nav_basis?>favicon.ico"
type="image/x-icon">
<LINK rel="shortcut icon" href="<?=$nav_basis?>favicon.ico"
type="image/x-icon">
<LINK rel="stylesheet" href="<?=$nav_basis?>lib/zaan.css"
type="text/css">
and head_2.php would look like:

</HEAD>
<BODY>
<div>

etcetera, in short: navigational elements with css formatting.

The main point is the variable $nav_basis, which is needed because not
all my files are in the same directory, and I would really would like
to have one file with standard stuff that works throughout the site as
it should. You might suggest using the <BASE> tag in html, but that is
no good: many files on the site are older and large html files with
ample relative crossreferences, which will irrevocably get broken by
such a tag, not to mention get a lot more confusing during future
updates.

My problem now is that Apache, or its PHP module won't properly parse
the PHP that I require(). I do not understand this. The PHP manual
seems to imply that PHP code in an require()ed file will be executed if
tagged properly, but I am having no luck.
As a result, the source file sent to my browser (by Apache, mind you,
not the local filesystem) contains the two head_x.php files as clear
text, showing <?php tags and everything as they are in the source file,
and nothing executed, obviously.
PHP code that I'd write in the main file (text.php) would get executed,
however.
include() shows the same behaviour.

I wonder what the problem is here. Is it my installation of PHP that is
faulty, is it something that I forgot, is it something else?

Can anybody help?

Thanks in advance,
Zaan


Jul 17 '05 #6

P: n/a
"Saving as Unicode" usually means saving as UCS-16. It's a 2-byte encoding.
When you save your PHP file as Unicode, the content becomes

<[]?[]p[]h[]p[] [] .... ?[]>[]

where [] is a null character. The PHP parser doesn't see the sequence
"<?php" therefore the code doesn't get parsed.

Uzytkownik "Zaan" <removethis_zaan_andthistoo@removethis_gmx.net_and thistoo>
napisal w wiadomosci
news:010220042103440168%removethis_zaan_andthistoo @removethis_gmx.net_andthi
stoo...
In article <Hq********************@comcast.com>, Chung Leong
<ch***********@hotmail.com> wrote:
The text editor saved your .php file as Unicode?

It was. Disabling 'Encode as Unicode' solved the problem. A very good
suggestion! Thanks a lot for that. Do you happen to know why this
problem occured?

Zaan


Uzytkownik "Zaan" <removethis_zaan@removethis_gmx.net> napisal w wiadomosci news:300120041643149487%removethis_zaan@removethis _gmx.net...

[I'm working on PHP version 4.3.4 (which may be of importance, I don't
know). It's the vanilla precompiled www.entropy.ch release for Mac OS
X.]

Hello,

My issue is the following: to promote consistency on a site I'm
building, I decided to go for a php scheme where some recurring
elements (navigation, mostly) are written in a file of their own, which would then get called from each file needing it by the function
require(). The following example may make this clear (the HTML is
clipped somewhat, but is W3C compliant in full...):

Suppose this is the main file, text.php
<?php require('./lib/head_1.php'); ?>
<TITLE>text</TITLE>
<?php require('./lib/head_2.php'); ?>
the actual body text, html formatted, would go here.
<?php require './lib/foot.php'; ?>
Then, head_1.php would look like:
<?php $nav_basis = "http://localhost/~username/; ?> // will
change once the site is done and is uploaded to the actual server, of
course.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<LINK rel="icon" href="<?=$nav_basis?>favicon.ico"
type="image/x-icon">
<LINK rel="shortcut icon" href="<?=$nav_basis?>favicon.ico"
type="image/x-icon">
<LINK rel="stylesheet" href="<?=$nav_basis?>lib/zaan.css"
type="text/css">
and head_2.php would look like:

</HEAD>
<BODY>
<div>

etcetera, in short: navigational elements with css formatting.

The main point is the variable $nav_basis, which is needed because not
all my files are in the same directory, and I would really would like
to have one file with standard stuff that works throughout the site as
it should. You might suggest using the <BASE> tag in html, but that is
no good: many files on the site are older and large html files with
ample relative crossreferences, which will irrevocably get broken by
such a tag, not to mention get a lot more confusing during future
updates.

My problem now is that Apache, or its PHP module won't properly parse
the PHP that I require(). I do not understand this. The PHP manual
seems to imply that PHP code in an require()ed file will be executed if tagged properly, but I am having no luck.
As a result, the source file sent to my browser (by Apache, mind you,
not the local filesystem) contains the two head_x.php files as clear
text, showing <?php tags and everything as they are in the source file, and nothing executed, obviously.
PHP code that I'd write in the main file (text.php) would get executed, however.
include() shows the same behaviour.

I wonder what the problem is here. Is it my installation of PHP that is faulty, is it something that I forgot, is it something else?

Can anybody help?

Thanks in advance,
Zaan


Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.