SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Okay, this problem is stupid, stupid, and dumb, but I just can't figure it out.

    index.php:

    Code:
    $x = "some string";
    $y = "another some string";
    $z = "a third some string";
    include ("header.php");
    header.php:

    Code:
    <HTML> and other stuff
    <? echo "$x, $y, $z ?>
    For some reason, that echo statement returns NOTHING!!!! This is simply beacuse of the include, and I cannot figure out what the heck is wrong! The variables work both before and after the include, but returns nothing when placed into header.php! Pelase help, before I go debugging-crazy.
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I'm pretty new to web programming with PHP - but that's not the way I would do it. I'm not saying its wrong - just that my mind would tackle it differently.

    I would probably write a function
    Code:
    function print_header($x, $y, $z) {
      // do stuff
       echo $x $y $z;
    }
    and stick that in a file called header.php and call it from my main script.

    But anyway, just guessing here but maybe in your file header.php use this:
    Code:
    <html stuff>
    <?
    global $x, $y, $z;
    echo "$x, $y, $z 
    ?>

  3. #3
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The global() thingy solved it, thanks! Never seen that before - need to look it up later.

    heh - I'd better learn PHP from scratch instead of this hard way.
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nah - the hard way is more satisfying


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
  •