SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict trican's Avatar
    Join Date
    Sep 2003
    Location
    someplace
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with echo'ing a php variable in a simple template

    Hi all,

    I was reading through the sitepoint book on php and mysql, and I was trying to write a simple template as per chapter 4 but I'm having a problem. A snippet of code is shown below, its probably something silly I'm doing wrong


    index.php
    Code:
        // $page is decoded from url and is verified to be as expected
        //... some other stuff
        $title = '$page';
        include 'page.tpl.php';
    page.tpl.php

    Code:
    <html>
    <title>
    <?php echo $title; ?>
    </title>
    </html>
    However the title is always blank - what am I doing wrong?

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    $page hasnt been defined as anything in your code, thats why its alway blank, I suspect the code in the book was more an example than a working model.

    Add this line to the top of your index.php

    PHP Code:
    $page 'this is the page title'
    you also want to remove the quotes around $page, that makes it a string not a variable
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    989
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    Variables aren't expanded in single quotes, not that quotes are needed here.

    Try

    PHP Code:
    $title $page

  4. #4
    SitePoint Addict trican's Avatar
    Join Date
    Sep 2003
    Location
    someplace
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks I think thats probably it, if its not I'll let you know.


    Many thanks again!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •