Template wrapping and implodes

Posted on 2008-11-03
Last Modified: 2008-11-03
Im not to sure how this works, i been seeings pieces of code on this and im still at a loss why this is used instead of includes. This is the type of pieces of codes i been looking at

$page1 = implode("", file("../templ/members/header.htt"));
$page2 = implode("", file("../templ/footer.htt"));
$pagads = implode("", file("../templ/ads.htt"));

Is it used like this? theres a template file, that file is put onto a page then you call these 3 files which already have the postioning in a differnt file. Is it somthing like this?
Question by:Lee-Bartlett
    LVL 82

    Expert Comment

    >>$page1 = implode("", file("../templ/members/header.htt"));
    that is just putting the contents of header.htt into the variable $page1. It does NOT automatically send the content to the browser. So, somewhere down the line it must explicitly be doing:
    echo $page;

    or perhaps is extracting some portion of the page only and echoing only the desired portion. The same applies to $page2 and $pageads

    Author Comment

    Im still a little confused, are these varibles stored in like a functions folder or somthing. if you got a link to a page which explains the structuer, any more information would be greate
    LVL 82

    Accepted Solution

    >>are these varibles stored in like a functions folder or somthing
    I don't understand what you are asking

    >>if you got a link to a page which explains the structuer
    No link. The concept is simple actually. To clarify further, consider this:
    $temp="hello world";

    $temp is just a variable and you are "saving/storing" a string in it. The file() function will open the file you specify and will return an array with the file contents. Each array element correspondes to one line of content. implode() then "joins" those lines of content. So what you posted is equivalent to:

    $temp = implode("",$content);

    at this point $temp contains "helloword", but is not automatially echoed. Thus far you have just stored a string value into $temp, but if you need to echo it, you need to do so explicitly:
    echo $temp;

    Author Comment

    Ty to my first question, i mean, if i wanted to use the file for like 9 pages i would be able to use the implode that file onto my page

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to count occurrences of each item in an array.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now