943,704 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 499
  • PHP RSS
Mar 17th, 2009
0

common webpage content

Expand Post »
Hi,
I'm new to php.I had to include common content to a lot of webpages in my website like menubar etc. and i was told i could load them dynamically from a single file using php.Can someone help me with this?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
AutoC is offline Offline
74 posts
since Sep 2008
Mar 17th, 2009
0

Re: common webpage content

You can either use require_once to include another file, or if you want something more fancy, you could use templates (smarty for example).
Sponsor
Featured Poster
Reputation Points: 550
Solved Threads: 728
Bite my shiny metal ass!
pritaeas is offline Offline
4,166 posts
since Jul 2006
Mar 17th, 2009
0

Re: common webpage content

As a beginner, I suggest you use the function "require" like this:

php Syntax (Toggle Plain Text)
  1. (require "includes/common.php");
Yes, require has a different syntax, to avoid future problems, always surround the hole statement with parenthesis.
Last edited by kadimi; Mar 17th, 2009 at 4:38 pm.
Reputation Points: 20
Solved Threads: 1
Newbie Poster
kadimi is offline Offline
10 posts
since Mar 2009
Mar 17th, 2009
0

Re: common webpage content

Click to Expand / Collapse  Quote originally posted by kadimi ...
As a beginner, I suggest you use the function "require" like this:

php Syntax (Toggle Plain Text)
  1. (require "includes/common.php");
Yes, require has a different syntax, to avoid future problems, always surround the hole statement with parenthesis.
What future problems are you talking about ? Could you explain this a bit better ?
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Mar 17th, 2009
1

Re: common webpage content

This works fine:
php Syntax (Toggle Plain Text)
  1. if( (require "sql.php") && 1)
  2. echo "success";


Whereas this produces a fatal error:
php Syntax (Toggle Plain Text)
  1. if( require("sql.php") && 1)
  2. echo "success";
the error:
Quote ...
Fatal error: require() [function.require]: Failed opening required '1' (include_path='.;C:\php5\pear') in D:\wamp\www\test\index.php on line 2
Failed opening required '1' ... huh

-----------------------
From the PHP manual for include() (same rules apply for require):

Because include() is a special language construct, parentheses are not needed around its argument. Take care when comparing return value.

http://www.php.net/manual/en/function.include.php
Reputation Points: 20
Solved Threads: 1
Newbie Poster
kadimi is offline Offline
10 posts
since Mar 2009
Mar 17th, 2009
0

Re: common webpage content

I haven't seen anyone using require or include inside a brace like this though.
php Syntax (Toggle Plain Text)
  1. <?php
  2. (include "db.php");
  3. (require "db.php");
  4. ?>
But the point to be noted is, include and require do return a value on successful inclusion. That return value is OK . Strange. I didn't know that I wonder what would be the return value on failure.
Also, include and require are not functions. They are language constructs. Hmm! Not bad to learn few new things @ 2-30 am ? Eh ?
Last edited by nav33n; Mar 17th, 2009 at 6:05 pm.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Mar 17th, 2009
0

Re: common webpage content

Yes, I was wrong, these are language constructs.

I wrote "&& 1", the "1" could any arbitrary PHP expression...
Reputation Points: 20
Solved Threads: 1
Newbie Poster
kadimi is offline Offline
10 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: tomcat configuration
Next Thread in PHP Forum Timeline: Pointing to subdomain to main domain





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC