Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何给文本上色_Php_Html_Colors_Echo - Fatal编程技术网

Php 如何给文本上色

Php 如何给文本上色,php,html,colors,echo,Php,Html,Colors,Echo,我有这个代码,可悲的是我不能改变任何东西或在课堂之外添加STUDENT。我只能在STUDENT内部修改,不能更改私有字段。但是,我需要以红色显示字段$nume的值。想法 class STUDENT { private $nume,$prenume; // Constructor public function __construct($nume , $prenume){ $this->nume=$nume; $this->p

我有这个代码,可悲的是我不能改变任何东西或在课堂之外添加
STUDENT
。我只能在
STUDENT
内部修改,不能更改私有字段。但是,我需要以红色显示字段
$nume
的值。想法

class STUDENT {
    private $nume,$prenume;
    // Constructor 
    public function __construct($nume , $prenume){ 
        $this->nume=$nume;
        $this->prenume=$prenume;            
    }

    public function __toString(){
        return $this->nume.".".$this->prenume;

    }


}

$student = new STUDENT("mr","Jack");  
echo "student: ". $student ."<hr/>"; 
班级学生{
私人$nume,$prenume;
//建造师
公共函数构造($nume,$prenume){
$this->nume=$nume;
$this->prenume=$prenume;
}
公共函数{
返回$this->nume.“.”$this->prenume;
}
}
$student=新生(“先生”、“杰克”);
回声“学生:”$学生“
”;
您是否尝试过

public function __toString(){
    $red = '<span style="color: red;">' . $this->nume . '</span>';
    return $red.".".$this->prenume;

}
公共函数{
$red=''.$this->nume';
返回$red.“.”$this->prenume;
}
你有没有试过

public function __toString(){
    $red = '<span style="color: red;">' . $this->nume . '</span>';
    return $red.".".$this->prenume;

}
公共函数{
$red=''.$this->nume';
返回$red.“.”$this->prenume;
}
你有没有试过

public function __toString(){
    $red = '<span style="color: red;">' . $this->nume . '</span>';
    return $red.".".$this->prenume;

}
公共函数{
$red=''.$this->nume';
返回$red.“.”$this->prenume;
}
你有没有试过

public function __toString(){
    $red = '<span style="color: red;">' . $this->nume . '</span>';
    return $red.".".$this->prenume;

}
公共函数{
$red=''.$this->nume';
返回$red.“.”$this->prenume;
}

您可以将属性公开,以便从外部访问它们,如下所示:

class STUDENT 
{
    public $nume;
    public $prenume;

    // Constructor 
    public function __construct($nume , $prenume)
    { 
        $this->nume=$nume;
        $this->prenume=$prenume;            
    }

    public function __toString()
    {
        return $this->nume.".".$this->prenume;
    }
}

$student = new STUDENT("mr","Jack");  
echo "<span style='color:red'>student: ". $student->nume ."</span><hr/>"; 
$student = new STUDENT("mr","Jack");  
$student->displayNume();

您可以将属性设置为公共属性,以便从外部访问它们,如下所示:

class STUDENT 
{
    public $nume;
    public $prenume;

    // Constructor 
    public function __construct($nume , $prenume)
    { 
        $this->nume=$nume;
        $this->prenume=$prenume;            
    }

    public function __toString()
    {
        return $this->nume.".".$this->prenume;
    }
}

$student = new STUDENT("mr","Jack");  
echo "<span style='color:red'>student: ". $student->nume ."</span><hr/>"; 
$student = new STUDENT("mr","Jack");  
$student->displayNume();

您可以将属性设置为公共属性,以便从外部访问它们,如下所示:

class STUDENT 
{
    public $nume;
    public $prenume;

    // Constructor 
    public function __construct($nume , $prenume)
    { 
        $this->nume=$nume;
        $this->prenume=$prenume;            
    }

    public function __toString()
    {
        return $this->nume.".".$this->prenume;
    }
}

$student = new STUDENT("mr","Jack");  
echo "<span style='color:red'>student: ". $student->nume ."</span><hr/>"; 
$student = new STUDENT("mr","Jack");  
$student->displayNume();

您可以将属性设置为公共属性,以便从外部访问它们,如下所示:

class STUDENT 
{
    public $nume;
    public $prenume;

    // Constructor 
    public function __construct($nume , $prenume)
    { 
        $this->nume=$nume;
        $this->prenume=$prenume;            
    }

    public function __toString()
    {
        return $this->nume.".".$this->prenume;
    }
}

$student = new STUDENT("mr","Jack");  
echo "<span style='color:red'>student: ". $student->nume ."</span><hr/>"; 
$student = new STUDENT("mr","Jack");  
$student->displayNume();


字体已经被弃用了,不是吗?如果我在写的话,我很可能会使用css类,但我会根据问题的OOP性质给出OP答案。我不想通过添加css文件、添加div之类的东西来使这个答案复杂化。我希望我的答案能找到问题的根源,OP能找出他想怎么做红色部分:)好吧,你可以只使用
风格
属性,我不认为它比这更复杂,但是,更符合最新情况。无意冒犯。)@Notulysses LOL。我真的不记得上次我试图格式化某个东西而不将其粘贴到CSS文件中是什么时候了。然而,我已经将它改为一个span,并使用了一个style属性:)然后+1,我的答案没有意义)字体被弃用了,不是吗?如果我正在编写它,我很可能会使用css类,但我会根据问题的OOP性质给出OP答案。我不想通过添加css文件、添加div之类的东西来使这个答案复杂化。我希望我的答案能找到问题的根源,OP能找出他想怎么做红色部分:)好吧,你可以只使用
风格
属性,我不认为它比这更复杂,但是,更符合最新情况。无意冒犯。)@Notulysses LOL。我真的不记得上次我试图格式化某个东西而不将其粘贴到CSS文件中是什么时候了。然而,我已经将它改为一个span,并使用了一个style属性:)然后+1,我的答案没有意义)字体被弃用了,不是吗?如果我正在编写它,我很可能会使用css类,但我会根据问题的OOP性质给出OP答案。我不想通过添加css文件、添加div之类的东西来使这个答案复杂化。我希望我的答案能找到问题的根源,OP能找出他想怎么做红色部分:)好吧,你可以只使用
风格
属性,我不认为它比这更复杂,但是,更符合最新情况。无意冒犯。)@Notulysses LOL。我真的不记得上次我试图格式化某个东西而不将其粘贴到CSS文件中是什么时候了。然而,我已经将它改为一个span,并使用了一个style属性:)然后+1,我的答案没有意义)字体被弃用了,不是吗?如果我正在编写它,我很可能会使用css类,但我会根据问题的OOP性质给出OP答案。我不想通过添加css文件、添加div之类的东西来使这个答案复杂化。我希望我的答案能找到问题的根源,OP能找出他想怎么做红色部分:)好吧,你可以只使用
风格
属性,我不认为它比这更复杂,但是,更符合最新情况。无意冒犯。)@Notulysses LOL。我真的不记得上次我试图格式化某个东西而不将其粘贴到CSS文件中是什么时候了。然而,我已经将其更改为一个span,并使用了一个style属性:)然后+1,我的答案没有意义)这非常好。如何将彩色文本设置为粗体?非常感谢。多亏了大家。冒着做不符合逻辑的事情的风险。我做了这个:$red='''''''$这个->nume.“.”;使用内嵌css,你也可以这样做:。。。最好在另一个文件中使用css。如果你对CSS感兴趣的话,就在网上看看CSS应该是如何编写的。这很好。如何将彩色文本设置为粗体?非常感谢。多亏了大家。冒着做不符合逻辑的事情的风险。我做了这个:$red='''''''$这个->nume.“.”;使用内嵌css,你也可以这样做:。。。最好在另一个文件中使用css。如果你对CSS感兴趣的话,就在网上看看CSS应该是如何编写的。这很好。如何将彩色文本设置为粗体?非常感谢。多亏了大家。冒着做不符合逻辑的事情的风险。我做了这个:$red='''''''$这个->nume.“.”;使用内嵌css,你也可以这样做:。。。最好在另一个文件中使用css。如果你对CSS感兴趣的话,就在网上看看CSS应该是如何编写的。这很好。如何将彩色文本设置为粗体?非常感谢。多亏了大家。冒着做不符合逻辑的事情的风险。我做了这个:$red='''''''$这个->nume.“.”;而且是