什么';这个PHP怎么了?什么也没有出现
我正在努力学习PHP,所以我很可能犯了一个非常初级的错误 基本上,我有一个page.php文件,它是我想要创建的页面的一个类文件,我想将它包含在我的home.php页面中(我使用require函数来实现)。然而,什么也没有出现。我是根据我正在读的一本书来做这件事的,它在那里似乎工作得很好 page.php:什么';这个PHP怎么了?什么也没有出现,php,Php,我正在努力学习PHP,所以我很可能犯了一个非常初级的错误 基本上,我有一个page.php文件,它是我想要创建的页面的一个类文件,我想将它包含在我的home.php页面中(我使用require函数来实现)。然而,什么也没有出现。我是根据我正在读的一本书来做这件事的,它在那里似乎工作得很好 page.php: <?php class Page { // attributes public $content; public $title = "TLA Consulti
<?php
class Page {
// attributes
public $content;
public $title = "TLA Consulting Pty Ltd";
public $keywords = "TLA Consulting, Three Letter Abbreviation, some of my best friends are search engines";
public $buttons = array("Home" => "home.php", "Contact" => "contact.php", "Services" => "services.php", "Site Map" => "map.php");
public function __set($name, $value) {
$this->$name = $value;
}
public function display() {
echo "<html>\n<head>\n";
$this->displayTitle();
$this->displayKeywords();
$this->displayStyle();
echo "</head>\n<body>\n";
$this->displayHeader();
$this->displayMenu($this->buttons); // try this line without giving it the parameter
echo $this->content;
$this->displayFooter();
echo "</body>\n</html>";
}
public function displayTitle() {
echo "<title>$this->title</title>";
}
public function displayKeywords() {
echo "<meta name=\"keywords\" content=\"$this->keywords\" />";
}
public function displayStyle() {
?>
<style>
h1 {
color: white;
font-size: 24px;
text-align: center;
font-family: helvetica, arial, sans-serif;
}
.menu {
color: white;
font-size: 12px;
text-align: center;
font-family: helvetica, arial, sans-serif;
font-weight: bold;
}
td {
background-color: black;
}
p {
color: black;
font-size: 12px;
text-align: justify;
font-family: helvetica, arial, sans-serif;
}
</style>
<?php
}
public function displayHeader() {
?>
<table width="100%" cellpadding="12" cellspacing="0" border="0">
<tr bgcolor="black">
<td aling="left"><img src="http://i.imgur.com/xBrUZ.png" alt="Iron Man's finger" /></td>
<td><h1>TLA Consulting Pty Ltd</h1></td>
</tr>
</table>
<?php
}
public function displayMenu($buttons) {
echo "<table width=\"100%\" bgcolor=\"white\">\n";
echo "<tr>\n";
// calculate button size
$width = 100 / count($buttons);
while (list($name, $url) = each($buttons)) {
$this -> displayButton($width, $name, $url, !this->IsURLCurrentPage($url));
}
echo "</tr>\n</table>\n";
}
public function IsURLCurrentPage($url) {
if (!strpos($_SERVER['PHP_SELF'], $url)) {
return false;
}
else {
return true;
}
}
public function displayButton($width, $name, $url, $active = true) {
if ($active) {
echo "<td width=\"".$width."%\">
<a href=\"$url\"><img src=\"http://i.imgur.com/xBrUZ.png\" alt=\"$name\" /></a>
<a href=\"$url\"><span class=\"menu\">$name</span></a>
</td>";
}
else {
echo "<td width=\"".$width."%\">
<img src=\"http://i.imgur.com/xBrUZ.png\" />
<span class=\"menu\">$name</span>
</td>";
}
}
public function displayFooter() {
echo "<p>I am a footer ololz</p>";
}
}
?>
h1{
颜色:白色;
字体大小:24px;
文本对齐:居中;
字体系列:helvetica、arial、无衬线字体;
}
.菜单{
颜色:白色;
字体大小:12px;
文本对齐:居中;
字体系列:helvetica、arial、无衬线字体;
字体大小:粗体;
}
运输署{
背景色:黑色;
}
p{
颜色:黑色;
字体大小:12px;
文本对齐:对齐;
字体系列:helvetica、arial、无衬线字体;
}
特拉咨询私人有限公司
home.php:
<?php
require("page.php");
$homepage = new Page();
$homepage->content = "<p>Hi there, I like blueberries greatlly.</p>
<p>I hope you'll join me in loving blueberries!</p>"
$homepage->display();
?>
两个问题:
应该是this
在$this
的第86行page.php
- 在
…蓝莓的末尾需要一个分号 “
如果未打开,您可能看不到错误。在home.php文件中,您在ine 10中缺少一个分号 在page.php文件中,第86行缺少字符“$”
$this -> displayButton($width, $name, $url, !$this->IsURLCurrentPage($url));
您使用php的开头和结尾不一致 例如:
public function displayStyle() {
?>
<style>
h1 {
color: white;
font-size: 24px;
text-align: center;
font-family: helvetica, arial, sans-serif;
}
.menu {
color: white;
font-size: 12px;
text-align: center;
font-family: helvetica, arial, sans-serif;
font-weight: bold;
}
td {
background-color: black;
}
p {
color: black;
font-size: 12px;
text-align: justify;
font-family: helvetica, arial, sans-serif;
}
</style>
<?php
}
公共函数displayStyle(){
?>
h1{
颜色:白色;
字体大小:24px;
文本对齐:居中;
字体系列:helvetica、arial、无衬线字体;
}
.菜单{
颜色:白色;
字体大小:12px;
文本对齐:居中;
字体系列:helvetica、arial、无衬线字体;
字体大小:粗体;
}
运输署{
背景色:黑色;
}
p{
颜色:黑色;
字体大小:12px;
文本对齐:对齐;
字体系列:helvetica、arial、无衬线字体;
}
您是否打开了错误报告?是否有任何错误?可能是因为home.php中的这一行没有分号。$homepage->content=“您好,我非常喜欢蓝莓。我希望您和我一起喜欢蓝莓"
Parse error:syntax error,第86Oh行page.php中意外的T_OBJECT_运算符,效果很好。我想我仍然在用Java思维。我现在要在手背上画一个大的美元符号。还添加了分号,还有错误报告。为彻底的答案干杯。事实上,我使用的服务器是我们的uni我不能改变这一点,对吗?试着把错误报告(E_ALL)
放在home.php
的顶部。我觉得这看起来很奇怪,但这是这本书告诉我的方法。这是一个屏幕截图。
<?php
public function displayStyle() {
echo "<style>".
"h1 {".
"color: white;";
}
?>