直接首尾放<?php ?>不就好了吗,
就算放很多个<?php ?>,怎么还能从fuction中间穿过去结尾呢。再怎么着也应该把方法完整的囊括啊,这function一半在上一个<?php ?>,另一半在下一个<?php ?>里。
是书里写错了还是什么特殊的写法?
<?php
class Page
{
  // class Page's 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"
                    );  // class Page's operations
  public function __set($name, $value)
  {
    $this->$name = $value;
  }  public function Display()
  {
    echo "<html>\n<head>\n";
    $this -> DisplayTitle();
    $this -> DisplayKeywords();
    $this -> DisplayStyles();
    echo "</head>\n<body>\n";
    $this -> DisplayHeader();
    $this -> DisplayMenu($this->buttons);
    echo $this->content;
    $this -> DisplayFooter();
    echo "</body>\n</html>\n";
  }  public function DisplayTitle()
  {
    echo "<title>".$this->title."</title>";
  }  public function DisplayKeywords()
  {
    echo "<meta name=\"keywords\" 
          content=\"".$this->keywords."\"/>";
  }  public function DisplayStyles()
  { 
?>   
  <style>
    h1 {
     color:white; font-size:24pt; text-align:center; 
        font-family:arial,sans-serif
    }
    .menu {
     color:white; font-size:12pt; text-align:center; 
        font-family:arial,sans-serif; font-weight:bold
    }
    td {
     background:black
    }
    p {
     color:black; font-size:12pt; text-align:justify; 
        font-family:arial,sans-serif
    }
    p.foot {
     color:white; font-size:9pt; text-align:center; 
        font-family:arial,sans-serif; font-weight:bold
    }
    a:link,a:visited,a:active {
     color:white
    }
  </style>
<?php
  }  public function DisplayHeader()
  { 
?>   
  <table width="100%" cellpadding="12" 
         cellspacing="0" border="0">
  <tr bgcolor ="black">
    <td align ="left"><img src = "logo.gif" /></td>
    <td>
        <h1>TLA Consulting Pty Ltd</h1>
    </td>
    <td align ="right"><img src = "logo.gif" /></td>
  </tr>
  </table>
<?php
  }  public function DisplayMenu($buttons)
  {
    echo "<table width=\"100%\" bgcolor=\"white\" 
          cellpadding=\"4\" cellspacing=\"4\">\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";
    echo "</table>\n";
  }  public function IsURLCurrentPage($url)
  {
    if(strpos($_SERVER['PHP_SELF'], $url )==false)
    {
      return false;
    }
    else
    {
      return true;
    }
  }  public function 
      DisplayButton($width,$name,$url,$active = true)
  {
    if ($active) {
      echo "<td width = \"".$width."%\">
      <a href=\"".$url."\">
      <img src=\"s-logo.gif\" alt=\"".$name."\" border=\"0\" /></a>
      <a href=\"".$url."\"><span class=\"menu\">".$name."</span></a>
      </td>";
    } else {
      echo "<td width=\"".$width."%\">
      <img src=\"side-logo.gif\">
      <span class=\"menu\">".$name."</span>
      </td>";
    }  
  }  public function DisplayFooter()
  {
?>
<table width="100%" bgcolor="black" cellpadding="12" border="0">
<tr>
<td>
    <p class="foot">&copy; TLA Consulting Pty Ltd.</p>
    <p class="foot">Please see our <a href ="">legal 
    information page</a></p>
</td>
</tr>
</table>
<?php
  }
}
?>

解决方案 »

  1.   

    好了,我知道了。是不是因为table还有CSS只能放在html页面,所以必须先<?php,然后下边再?>
    没看仔细,我太逗比了
      

  2.   

    在 <?php  ?> 里边的是 php 代码
    在 <?php  ?> 外边的是 html 代码
    没有什么奇怪,php 就是这样设计的
      

  3.   

    你也可以用php的echo输出,像你主贴中的有些方法一样,就不用分开了。
      

  4.   

    <?php  ?> 里边的是 php 代码
    这个是用于区分php与其他html的,语法定义就是这样。
      

  5.   

    可以用定介符输出,你用echo的话太麻烦了