common webpage content

Reply

Join Date: Sep 2008
Posts: 62
Reputation: AutoC is an unknown quantity at this point 
Solved Threads: 0
AutoC AutoC is offline Offline
Junior Poster in Training

common webpage content

 
0
  #1
Mar 17th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 883
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 144
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: common webpage content

 
0
  #2
Mar 17th, 2009
You can either use require_once to include another file, or if you want something more fancy, you could use templates (smarty for example).
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 10
Reputation: kadimi is an unknown quantity at this point 
Solved Threads: 1
kadimi's Avatar
kadimi kadimi is offline Offline
Newbie Poster

Re: common webpage content

 
0
  #3
Mar 17th, 2009
As a beginner, I suggest you use the function "require" like this:

  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.
Need tech support? Ask Nabil
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: common webpage content

 
0
  #4
Mar 17th, 2009
Originally Posted by kadimi View Post
As a beginner, I suggest you use the function "require" like this:

  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 ?
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 10
Reputation: kadimi is an unknown quantity at this point 
Solved Threads: 1
kadimi's Avatar
kadimi kadimi is offline Offline
Newbie Poster

Re: common webpage content

 
1
  #5
Mar 17th, 2009
This works fine:
  1. if( (require "sql.php") && 1)
  2. echo "success";


Whereas this produces a fatal error:
  1. if( require("sql.php") && 1)
  2. echo "success";
the error:
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
Need tech support? Ask Nabil
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: common webpage content

 
0
  #6
Mar 17th, 2009
I haven't seen anyone using require or include inside a brace like this though.
  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.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 10
Reputation: kadimi is an unknown quantity at this point 
Solved Threads: 1
kadimi's Avatar
kadimi kadimi is offline Offline
Newbie Poster

Re: common webpage content

 
0
  #7
Mar 17th, 2009
Yes, I was wrong, these are language constructs.

I wrote "&& 1", the "1" could any arbitrary PHP expression...
Need tech support? Ask Nabil
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum


Views: 356 | Replies: 6
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC