Echo in an include?

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

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's picture

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.

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. Wink

teammatt3's picture

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's picture

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

He has: 57 posts

Joined: Apr 2005

It is simple.

Can't you just do

<?php
include(URL.'header.php');
?>

That should work Wink

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.