Lassie Posted February 4, 2009 Share Posted February 4, 2009 I want to include variable mata data im my header by including the varaiablee from a page specific file. in the header i include a file to determine the page title and by passing this as a variable include the relevant page specific information. How do I write the include and echo the varaibles? The include include('./metadata/$title_metadata.php'); Header function <?php function do_html_header() { include ('./includes/title.inc.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Authorbank<?php if (isset($title)) echo"‚{$title}";?></title> <meta name="description"content=<?php echo"{$description};?>/> <meta name="keywords"content=<?php echo"{$keywords}";?>/> <link href="/authorbank/includes/layout.css" media="screen" rel="stylesheet" type="text/css" /> <link href="/authorbank/includes/menu.css" media="screen" rel="stylesheet" type="text/css />" <?php } title.inc.php [code] <?php $title = basename($_SERVER['SCRIPT_NAME'], '.php'); $title = str_replace('_', ' ', $title); if ($title == 'index') { $title = 'home'; } $title = ucwords($title); include ('./metadata/$title_metadata.php') ?> meta data [code] <?php $description="Authorbank Connecting Authors with Publishers"; $keywords="publishing, Finding a Publisher, Getting Published,writers, authors, submitting a book proposal"; ?> [/code] [/code] Quote Link to comment Share on other sites More sharing options...
gevans Posted February 4, 2009 Share Posted February 4, 2009 Your html is in a function, the variables taht you use inside taht function need to be passed to it function example() { return $foo; } $foo = 'test'; echo example();//nothing printed function example($foo) { return $foo; } $foo = 'test'; echo example($foo);//test printed Quote Link to comment Share on other sites More sharing options...
Lassie Posted February 4, 2009 Author Share Posted February 4, 2009 Right. see what u mean.However my include call is within the function so shouldnt that make the variables available in the function? Quote Link to comment Share on other sites More sharing options...
gevans Posted February 4, 2009 Share Posted February 4, 2009 Do you think you could post your code again? It's a bit messed up... Post the function, the included files and the files that calls the function Quote Link to comment Share on other sites More sharing options...
Lassie Posted February 4, 2009 Author Share Posted February 4, 2009 Ok this is the header function i include title.inc at the top. title.inc determines the page title we are on and the opens the relevant meta data file. This is where i need help to build the path to open the file and read the variables so they can be put in the meta tags. Header function do_html_header() { include ('./includes/title.inc.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Authorbank<?php if (isset($title)) echo"‚{$title}";?></title> <meta name="description"content=<?php echo{'$description'};?>/> <meta name="keywords"content=<?php echo{'$keywords'};?>/> <link href="/authorbank/includes/layout.css" media="screen" rel="stylesheet" type="text/css" /> <link href="/authorbank/includes/menu.css" media="screen" rel="stylesheet" type="text/css />" <?php } Title.inc.php <?php $title = basename($_SERVER['SCRIPT_NAME'], '.php'); $title = str_replace('_', ' ', $title); if ($title == 'index') { $title = 'home'; } $title = ucwords($title); //Build file path $path = './metadata/'; $path = $path.$title; //Read contents of file $data=fopen($path.$title,'r') or die('Cant open file'); $theData = fread($data,filesize($myFile)); fclose($data); ?> The meta data is in ./metadata/home.php for the first page. <?php $description="Authorbank Connecting Authors with Publishers"; $keywords="publishing, Finding a Publisher, Getting Published,writers, authors, submitting a book proposal"; ?> Quote Link to comment Share on other sites More sharing options...
gevans Posted February 4, 2009 Share Posted February 4, 2009 Is the title printing and not the description/keyword? Quote Link to comment Share on other sites More sharing options...
Lassie Posted February 4, 2009 Author Share Posted February 4, 2009 At present the errors are title.inc fails to open the file ie no such file exits and in the header there is a parse error on line 12 trying to echo the $description this is a link to my test site http:217.46.159.226/ab_dev/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.