Php 正文中出现的HTML标题信息
我创建了一个简单的网页,其中包括作为单独php文件的页眉和页脚,如下所示Php 正文中出现的HTML标题信息,php,html,header,Php,Html,Header,我创建了一个简单的网页,其中包括作为单独php文件的页眉和页脚,如下所示 <?php $PageName = "Home Page"; include $_SERVER['DOCUMENT_ROOT'] . "/MyPage/header.php"; include $_SERVER['DOCUMENT_ROOT'] . "/MyPage/footer.php";?> 这是标题 <?php print("<!DOCTYPE html>"); print("&
<?php
$PageName = "Home Page";
include $_SERVER['DOCUMENT_ROOT'] . "/MyPage/header.php";
include $_SERVER['DOCUMENT_ROOT'] . "/MyPage/footer.php";?>
这是标题
<?php
print("<!DOCTYPE html>");
print("<html lang='en-UK'>");
print("<head>");
print("<title>");
print($PageName);
print("");
print("</title>");
print("<meta http-equiv='content-type' content='text/html; charset=utf-8' >");
print("<meta name='viewport' content='width=device-width, initial-scale=1.0'>");
$CSSRoot = "/MyPage/StyleDefault.css";
print("<link rel='stylesheet' type='text/css' href=$CSSRoot>");
print("</head>");
print("<body>");
print("<h1>My Page</h1>");?>
这是您应该如何做到的
header.php
<!DOCTYPE html>
<html lang="en-UK">
<head>
<title><?php echo $PageName;?></title>
<meta http-equiv='content-type' content='text/html; charset=utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<link rel='stylesheet' type='text/css' href="<?php echo $CSSRoot;?>">
</head>
<body>
<?php
$PageName = "Home Page";
$CSSRoot = "/MyPage/StyleDefault.css";
include $_SERVER['DOCUMENT_ROOT'] . "/MyPage/header.php";
?>
<h1>My Page</h1>
<?php include $_SERVER['DOCUMENT_ROOT'] . "/MyPage/footer.php";?>
</body>
</html>
我的页面
footer.php
<!DOCTYPE html>
<html lang="en-UK">
<head>
<title><?php echo $PageName;?></title>
<meta http-equiv='content-type' content='text/html; charset=utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<link rel='stylesheet' type='text/css' href="<?php echo $CSSRoot;?>">
</head>
<body>
<?php
$PageName = "Home Page";
$CSSRoot = "/MyPage/StyleDefault.css";
include $_SERVER['DOCUMENT_ROOT'] . "/MyPage/header.php";
?>
<h1>My Page</h1>
<?php include $_SERVER['DOCUMENT_ROOT'] . "/MyPage/footer.php";?>
</body>
</html>
这应该行得通,我不知道为什么你想用php打印所有html标记,而你可以正常输出em。我相信我已经发现了问题,chrome中的sources面板显示,就在doctype和end body标记之前有两个字符(即页眉和页脚文件开始的位置),由红点表示,根据这是一个零宽度的不间断空间,我不知道它们是如何出现的,我似乎无法摆脱它们,但它们似乎是问题的原因
更新
环顾prolbem,php文件使用UFT-8 BOM(字节顺序标记)插入了有问题的字符,将其更改为UTF-8(在Notepadd++中编码)解决了问题,感谢所有帮助在php中打印每一行?为什么不在不需要像
那样调用它的地方关闭它,并使用html您的标题
?您是否尝试了页眉和页脚代码,但没有将它们包含在其他页面中?$CSSRoot
在页面中?为什么不在header.php
?我更喜欢在实际页面上分配它,而不是在页眉上,只是为了防止某些页面与header.php
不在同一目录中,所以分配正确的css URL很容易。我刚才尝试了您的建议,但问题仍然出现,我相信这与“;”它出现在header元素之后,尾端之前。您可以粘贴最新代码@FesteringDoubt吗?因为我不明白您遇到的问题,也可以尝试清空所有浏览器缓存我的页面
<?php
$PageName = "Home Page";
$CSSRoot = "/MyPage/StyleDefault.css";
include $_SERVER['DOCUMENT_ROOT'] . "/MyPage/header.php";
?>
<h1>My Page</h1>
<?php include $_SERVER['DOCUMENT_ROOT'] . "/MyPage/footer.php";?>
</body>
</html>