SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast Chip D's Avatar
    Join Date
    Nov 2000
    Location
    Ontario, Canada
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Having read Skunk's thread,Extremely cool (and easy) way of creating 'search engine friendly' URLs for scripts, I decided that I would use this technique for the new design of one of my sites. Now that I've reached a point that the site is very nearly ready, I've run into a small problem. The way the site operates is basically that there is one page (template), and the content changes depending on the value of the pageid variable. The content pages are then included into the main template. At the top of each include page are two variables, the page title, and the meta tags.

    What I was expecting to happen was for these variables to be passed from the included files to the main content page. Purpose being to give each page it's own title and meta tags. Annoyingly though these variables aren't being passed over to the main page. I thought PHP could do this, can it? Or am I just being stupid . . . again!

    I hope that makes sense, any help is greatly appreciated.
    Chip D
    ----------------------------------------------------
    Chances are what I think I'm typing is nothing like what I type.

  2. #2
    SitePoint Enthusiast Chip D's Avatar
    Join Date
    Nov 2000
    Location
    Ontario, Canada
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since my first post, I've continued to play around with a couple of test files that I was using to simulate the problem. they are test.in.php :
    PHP Code:
    <? $title "Testing"?>
    and testing.php
    PHP Code:
    <HTML>
    <HEAD>
    <TITLE>Untitled Document</TITLE>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
    </HEAD>

    <BODY BGCOLOR="#FFFFFF" TEXT="#000000">
    <?php require("test.inc.php"); ?>
    <?php 
    print("$title"); ?>
    </BODY>
    </HTML>
    If I use the script as it's shown above, it does what I'd expect it to and prints the word Testing on the page. However if I swap the two lines of PHP code around in the file testing.php to simulate the way they appear on the actual page,
    PHP Code:
    <?php print("$title"); ?>
    <?php 
    require("test.inc.php"); ?>
    the script just displays a blank screen. I thought that PHP would just take all of the included/required files then output the overall outcome of the combined variables, etc.

    I hope this explains my first post a bit better. I really don't want to have to go back and figure out how to rearrange all the code if I don't have to.

    Thanks,
    Chip D
    ----------------------------------------------------
    Chances are what I think I'm typing is nothing like what I type.

  3. #3
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I see what you are trying to do - but it's not going to work The contents of the required file will be placed in-line at the place where the require directive occurs. PHP can't rearange the order of the code for you. In effect this code:
    PHP Code:
    <HTML>
    <HEAD>
    <TITLE>Untitled*Document</TITLE>
    <META*HTTP-EQUIV="Content-Type"*CONTENT="text/html;*charset=iso-8859-1">
    </HEAD>

    <BODY*BGCOLOR="#FFFFFF"*TEXT="#000000">
    <?php*print("$title");*?>
    <?php*require
    ("test.inc.php");*?>
    </BODY>
    </HTML>
    Will be interpreted as:
    PHP Code:
    <HTML>
    <HEAD>
    <TITLE>Untitled*Document</TITLE>
    <META*HTTP-EQUIV="Content-Type"*CONTENT="text/html;*charset=iso-8859-1">
    </HEAD>
    <BODY*BGCOLOR="#FFFFFF"*TEXT="#000000">
    <?php*print("$title");*?>
    <?*$title*
    =*"Testing";*?>
    </BODY>
    </HTML>

  4. #4
    SitePoint Enthusiast Chip D's Avatar
    Join Date
    Nov 2000
    Location
    Ontario, Canada
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    D'oh!

    Thanks for confirming that for me. Now onto the task of re-arranging everything so that the $title variable will appear before it is required.

    Chip D
    ----------------------------------------------------
    Chances are what I think I'm typing is nothing like what I type.

  5. #5
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe instead of include() or require() the file you can just file() it into an array then set a while() loop.
    For example, store the title in the first line and say the 10 next lines are meta tags, format these lines as you wish. Echo the value of these data lines into the title and meta tags, then when it comes to including the main part of the file just do a while() loop or a foreach() from the 12th line to the last one, echo them all.

    I hope this was not too obscure I'm a beginner too, so my ways must look a bit bulky.
    [blogger: zengun] [blogware contributor: wordpress]


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
  •