我在PHP对象使用如下代码5个属性:格式的HTML表格回声输出
<?php
class Person
{
private $gender, $race, $height, $weight, $eyes_color;
public function start ($gender,$race,$height, $weight, $eyes_color)
{
$this->gender=$gender;
$this->race=$race;
$this->height=$height;
$this->weight=$weight;
$this->eyes_color=$eyes_color;
}
public function show_attributes()
{
return sprintf("%s, %s, %s, %s, %s", $this->gender, $this->race, $this->height, $this->weight,$this->eyes_color);
}
}
$person=new person();
?>
我用下面的HTML代码调用这个类现在
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Class Person</title>
</head>
<body>
<?php
require_once("Person.php");
$person->start("Male","Latin","1.83 cm","85 kg","Brown");
echo $person->show_attributes();
?>
</body>
</html>
,将打印出类似这样
Male, Latin, 1.83 cm, 85 kg, Brown
但我想打印出类似这样
--------------------------------------
|Male | Latin | 1.83 cm | 85 kg | Brown|
--------------------------------------
使用HTML表格。
我已经尝试了几件事,但是我不能让它发生。
有没有办法迫使
echo $person->show_attributes();
只显示一个属性,所以我可以从一个HTML细胞表里面打电话了吗?
谢谢。
你是否试过循环'$ person-> show_attributes()'并在表格中附加一个新的''? – pdoherty926