include variable & text

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tommyinnn
Forum Newbie
Posts: 1
Joined: Fri Jul 16, 2010 12:23 pm

include variable & text

Post by tommyinnn »

Hi everyone, I'm trying to create a include line using a variable and path
- this is to display my header

something like


<?php
$site = domain.com
include $site "." "/heading.php";
?>

so it would end up being
<?php include 'http://domain.com/heading.php'; ?>

thanks for any help any1 can give
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: include variable & text

Post by JakeJ »

Assuming you're trying to access content from the same site, try this instead:

Code: Select all

include('./directory/heading.php');
However if you have to do this many times with many sites, consider a function:

Code: Select all

function full_url($domain, $path, $filename) {
   $url = $domain.$path.$filename;
   return $url;
}
$full_url = function($domain, $path,$filename);
include($full_url);
I'm not entirely sure what you're trying to accomplish though, please clarify.
Post Reply