我在PHP中有一个具有5个属性的对象,使用以下代码:
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代码调用此类
Class Personrequire_once("Person.php");
$person->start("Male","Latin","1.83 cm","85 kg","Brown");
echo $person->show_attributes();
?>
现在,这将打印类似的内容
Male, Latin, 1.83 cm, 85 kg, Brown
但我想要打印像这样的东西
--------------------------------------
|Male | Latin | 1.83 cm | 85 kg | Brown|
--------------------------------------
使用HTML表格。
我尝试了几件事,但我无法实现。
有没有办法强迫
echo $person->show_attributes();
只显示一个属性,以便我可以从HTML单元格表中调用它?
感谢。