Reputation: 591
Hey I have a somewhat simple, i think, question... I am trying to pass html text into a PHP variable so that I can use the value over and over again without having to change the META tags, title and description for every single page entity which would all be different. I want to keep it all condensed into one header.php page which is always called, but the Meta tags must change according to the pages title and description.
so for example,
page 1 title = Chicken
index.php:
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/test/general.php');
include("header.php");
?>
<ul>
<li class="title"><?php $title = '?>Chicken<?php ';?> </li>
</ul>
</body>
</html>
general.php:
<?php
function siteinfo( $show='' ) {
echo get_siteinfo( $show, 'display' );
}
function get_siteinfo( $show = '', $filter = 'raw' ) {
switch( $show ) {
case 'title':
$output = $title;
break;
return $output;
}
?>
header.php:
<html>
<head>
<meta name="title" content="<?php siteinfo( 'title' ); ?>" />
</head>
<body>
i know this part is really jacked up, not sure how it should work... essentially, i want the HTML to be the function value: <?php $title = '?>Chicken<?php ';?>
but of course, the ' and second enclosing ' kill the whole function.
thanks!
Upvotes: 0
Views: 2488
Reputation: 33163
You're overthinking the problem a bit. Something like this should work for your purposes:
index.php:
<?php
$title = 'Chicken';
include("header.php");
?>
<ul>
<li class="title"><?php echo $title; ?></li>
</ul>
</body>
</html>
header.php:
<html>
<head>
<meta name="title" content="<?php echo $title; ?>" />
</head>
<body>
Upvotes: 1