Echo in an include?
I have no idea if this is possible...
I have this
<?php include ('header.php') ?>
And this
<?php
// Valid constant names
define("URL", "http://localhost/");
define("IMAGE", "http://localhost/images");
?>
How can I echo the constant in the include code?
This is what I tried but it didn't work.
<?php include (echo URL header.php) ?>
Is this possible? I want the include to be an exact file name without having to type in http://localhost everytime.
teammatt3 posted this at 23:51 — 4th November 2005.
He has: 2,102 posts
Joined: Sep 2003
Geez, I'm retarded. You have to connect to the include file where the constant is before you can USE the constant.
Nevermind, I figured out a different solution.
kazimmerman posted this at 23:57 — 4th November 2005.
He has: 698 posts
Joined: Jul 2005
If you could, please post your solution so anyone who may have the same problem in the future will see this post.
teammatt3 posted this at 23:59 — 4th November 2005.
He has: 2,102 posts
Joined: Sep 2003
Well, I am just gonna do it the hard way. Just type out http://localhost for all the links.
Busy posted this at 08:41 — 5th November 2005.
He has: 6,151 posts
Joined: May 2001
As you are including the file, do what ever needs to be done in it (including echo), so the include is the result as well.
Depending what your intentions are you should also look at require and/or include/require_once
cpellizzi posted this at 05:11 — 9th November 2005.
He has: 57 posts
Joined: Apr 2005
It is simple.
Can't you just do
<?php
include(URL.'header.php');
?>
That should work
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.