Results 1 to 3 of 3

Thread: Variables... Am I Doing Something Wrong?

  1. #1
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default Variables... Am I Doing Something Wrong?

    Hi,

    I'm trying to make a simple variable/HTML thing in my code, but I can't get it to work...

    Here's what I have:
    PHP Code:
    <?php
        $directory
    ='/site/folder'//Site Directory WITHOUT trailing slash.
        
    function global_head(){
    ?>
            <meta http-equiv="content-type" content="text/html; charset=utf-8" />
            <link rel="stylesheet" href="<?php echo $directory?>/sys/default.css" type="text/css" />
            <script type="text/javascript" src="<?php echo $directory?>/sys/jquery.min.js"></script>

    <?php
        
    }
    ?>
    All I get in my code for the HTML URL's is: /sys/whatever_the_file_is. The PHP isn't working...

    Can someone please tell me what I'm doing wrong...

    Thanks,
    X96
    Last edited by X96 Web Design; 06-13-2009 at 11:59 PM.
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

  2. #2
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    The variable directory is outside the variable scope of that function. To make it accessible, do the following:
    PHP Code:
    <?php
        $directory
    ='/site/folder'//Site Directory WITHOUT trailing slash.
        
    function global_head(){
        global 
    $directory;
    ?>

  3. The Following User Says Thank You to techietim For This Useful Post:

    X96 Web Design (06-13-2009)

  4. #3
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default

    Thank you, it works perfectly.

    // X96 \\
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

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
  •