DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   common webpage content (http://www.daniweb.com/forums/thread182007.html)

AutoC Mar 17th, 2009 10:00 am
common webpage content
 
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?

pritaeas Mar 17th, 2009 10:10 am
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).

kadimi Mar 17th, 2009 3:36 pm
Re: common webpage content
 
As a beginner, I suggest you use the function "require" like this:

(require "includes/common.php");
Yes, require has a different syntax, to avoid future problems, always surround the hole statement with parenthesis.

nav33n Mar 17th, 2009 4:08 pm
Re: common webpage content
 
Quote:

Originally Posted by kadimi (Post 827098)
As a beginner, I suggest you use the function "require" like this:

(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 ?

kadimi Mar 17th, 2009 4:44 pm
Re: common webpage content
 
This works fine:
if( (require "sql.php") && 1)
  echo "success";


Whereas this produces a fatal error:
if( require("sql.php") && 1)
  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

nav33n Mar 17th, 2009 5:05 pm
Re: common webpage content
 
I haven't seen anyone using require or include inside a brace like this though.
<?php
(include "db.php");
(require "db.php");
?>
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 ? ;)

kadimi Mar 17th, 2009 5:12 pm
Re: common webpage content
 
Yes, I was wrong, these are language constructs.

I wrote "&& 1", the "1" could any arbitrary PHP expression...


All times are GMT -4. The time now is 11:41 am.

Forum system based on vBulletin Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
©2003 - 2010 DaniWeb® LLC