Log in

View Full Version : Resolved Variables... Am I Doing Something Wrong?



X96 Web Design
06-13-2009, 11:11 PM
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
$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

techietim
06-13-2009, 11:53 PM
The variable directory is outside the variable scope of that function. To make it accessible, do the following:


<?php
$directory='/site/folder'; //Site Directory WITHOUT trailing slash.
function global_head(){
global $directory;
?>

X96 Web Design
06-13-2009, 11:59 PM
Thank you, it works perfectly.

// X96 \\