simple PHP question

Discussion in 'PHP' started by stats, May 26, 2007.

  1. #1
    Hi

    I know this is simple, but i just don't find the way ..

    in my page.php i have the folowing

    <?php
    $message = "hello world";
    include 'template.html';
    ?>

    and in my template.html i have the folowing

    <h1>$message</h1>


    so .. now i expect when i call page.php, i should see "hello world", but instead i see "$message" in my browser .. why is this ? how do i fix it ?

    Thanks
     
    stats, May 26, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Rename 'template.html' to 'template.php'.
     
    nico_swd, May 26, 2007 IP
  3. Weizheng

    Weizheng Peon

    Messages:
    93
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You must print the variable.

    Try this

    <h1><?=$message?></h1>
     
    Weizheng, May 26, 2007 IP
  4. Clive

    Clive Web Developer

    Messages:
    4,507
    Likes Received:
    297
    Best Answers:
    0
    Trophy Points:
    250
    #4
    Besides, your template.php should look like
    <h1><?php echo $message ?></h1>
    Code (markup):
     
    Clive, May 26, 2007 IP
  5. HuggyCT2

    HuggyCT2 Guest

    Messages:
    222
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    When including files if you have php inside that file you MUST have the .php extension on the included page. And as ^^ you can always escape from php and wirte html then carry on.

    You could just use:

    
    echo "<h1>$message</h1>";
    
    PHP:
    Glen
     
    HuggyCT2, May 26, 2007 IP