在PHP中使用箭头表示法显示不正确的页面

时间:2014-11-29 13:54:45

标签: php html notation

我对PHP编码很新,我一直在尝试一些课程,但我似乎无法解决这个问题。 我想显示一个我必须在课程中创建的页面,但似乎在第一个箭头符号实例后代码“分解”了。这是页面的简化版本(但具有相同的错误)。

<html>
    <head>
      <title> Hello World! </title>
    </head>
    <body>
        <p>
            <?php
                class Dog{
                    public $numLegs = 4;
                    public $name;
                    public function __constructor($name){
                           $this->name = $name;
                    }
                    public function greet(){
                        return "Hello! My name is " . $this->name . "!";
                    }
                }

                $Doug = new Dog("Doug");

                echo $Doug->greet();

            ?>
        </p>
    </body>
</html>

以下是Chrome中的输出: image

1 个答案:

答案 0 :(得分:0)

这是代码,

你必须改变构造函数以构建第11行

并使用.php扩展名保存此文件

希望你能得到答案

<html>
    <head>
      <title> Hello World! </title>
    </head>
    <body>
        <p>
            <?php
                class Dog{
                    public $numLegs = 4;
                    public $name;
                    public function __construct($name){
                           $this->name = $name;
                    }
                    public function greet(){
                        return "Hello! My name is " . $this->name . "!";
                    }
                }

                $Doug = new Dog("Doug");

                echo $Doug->greet();

            ?>
        </p>
    </body>
</html>