变量元描述

时间:2013-04-28 22:01:12

标签: php html5 include

在我正在制作的网站上,我有标题&页脚包括。我希望能够在网站的每个页面上使用不同的元描述,但这让我感到困惑。标题工作正常,但我想知道这是否因为引用了引号。

header.php代码是:

<!DOCTYPE html>

<head>

<meta charset="UTF-8">  
<title><?php echo $title; ?></title>
<meta name="description" content="<?php echo $desc; ?>">
<meta name="keywords" content="neurologist, neurologic, neurology, nervous system, brain, seizure, epilepsy, carpal tunnel, seattle, ballard, washington, wa, king county, swedish hospital">

index.php代码是:

<?php include ("header.php"); ?>
<?php $title = "Neurologic Clinic | Dr. Hal Rappaport | Seattle Neurologist"; ?>
<?php $desc = "Dr. Hal Rapport is a neurologist located in Seattle's Ballard neighborhood. He specializes in neurologic conditions and disorders and is also a certified psychologist"; ?>

您可以给予任何帮助。

3 个答案:

答案 0 :(得分:2)

这是因为您在包含标题后分配变量,因此请更改为

<?php $title = "Neurologic Clinic | Dr. Hal Rappaport | Seattle Neurologist"; ?>
<?php $desc = "Dr. Hal Rapport is a neurologist located in Seattle's Ballard neighborhood. He specializes in neurologic conditions and disorders and is also a certified psychologist"; ?>
<?php include ("header.php"); ?>

答案 1 :(得分:-1)

首先,定义 $title$desc。然后包含标题

<?php
    $title = "title";
    $desc = "description";

    include("header.php");
?>

答案 2 :(得分:-1)

您无需在每一行调用<?php ?>

<?php
$title = "Neurologic Clinic | Dr. Hal Rappaport | Seattle Neurologist";
$desc = "Dr. Hal Rapport is a neurologist located in Seattle's Ballard neighborhood. He specializes in neurologic conditions and disorders and is also a certified psychologist";
include ("header.php");
?>