0

I want to run the following code for practice but can't. What do you think is wrong? I expect a red text to appear. But that doesn't happen and the text will turn black

    <?php
class Myclass{
    public $font_size = "40px";
    public $font_color = "red";
    public $string_name = "just do it";
    public function print_string(){
        echo "<p style=font-size:".$this->font_size."; color:".$this->font_color.";>".$this->string_name."</p>";
    }
}
$foo = new Myclass;
echo $foo->print_string();

1 Answers1

0

The value of style property must in '', like this :

echo "<p style='font-size:".$this->font_size."; color:".$this->font_color.";'>".$this->string_name."</p>";
Mahefa
  • 418
  • 3
  • 12