Help with PHP includes and Variables

Discussion in 'PHP' started by DeluxeEdition, Sep 25, 2006.

  1. #1
    I'm new to PHP so please bare with me with me if this is an easy question, I tried searching but really didn't know what I was searching for.

    How would you do an include with PHP where the variable is called from the page not the template. I know some coldfusion so I'll try and give an example using that.

    On my web page (mypage.cfm) I would have the following:
    <cfset street="Elm">
    <cfset city="Chicago">
    <cfinclude="mytemplate.cfm">
    Code (markup):
    then on the template (mytemplate.cfm) I would have:

    <cfoutput>#street# #city#</cfoutput>
    Code (markup):
    that would output on mypage.cfm

    Elm Chicago
    Code (markup):
    How do I do this using PHP?
     
    DeluxeEdition, Sep 25, 2006 IP
  2. fsmedia

    fsmedia Prominent Member

    Messages:
    5,163
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    390
    #2
    fsmedia, Sep 25, 2006 IP
  3. DeluxeEdition

    DeluxeEdition Active Member

    Messages:
    308
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    58
    #3
    I don't have a form to post from.. this is just to create similar pages with different names and different content.

    I just want to create hard coded pages using a template and called variable.
     
    DeluxeEdition, Sep 26, 2006 IP
  4. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #4
    
    <?php
    
    $street="Elm";
    $city="Chicago";
    
    include 'mytemplate.php';
    
    ?>
    
    PHP:
    mytemplate.php

    
    <?php
    
    echo $street . " " . $city;
    
    ?>
    
    PHP:
    You can output html for formatting as well.

    php.net is a great resource for everything you may need to reference. If you know how to do something in the other language, you will know what functions to look for there. Here is the link to include...

    http://us3.php.net/manual/en/function.include.php
     
    noppid, Sep 26, 2006 IP
  5. DeluxeEdition

    DeluxeEdition Active Member

    Messages:
    308
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Thanks Noppid I wasn't even sure what I was looking for but that works perfect - Thanks
     
    DeluxeEdition, Sep 26, 2006 IP