코드는,
: 여기
<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>
은 크롬에서 출력
희망 하시겠습니까?
<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>
웹 서버가 PHP 파일로 해석해야한다는 것을 모르는 것처럼 보입니다. 아파치를 사용하고 있습니까? 파일 이름은 무엇입니까? – msturdy
이 페이지를 PHP와 같이 저장하십시오. 예 : index.php not index.html – dm4web
'__constructor'를'__construct'로 변경하십시오. 그렇지 않으면 샘플이 저에게 잘 돌아갑니다! 서버가 PHP를 지원하지 않거나'* .php'로 파일을 저장하지 않았다고 생각하십시오 – Rizier123