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();
3
  • kindly post what error you are receiving. Commented Nov 24, 2019 at 13:18
  • Does this answer your question? How to use css style in php Commented Nov 24, 2019 at 13:35
  • "What do you think is wrong?" - your use of string / attribute delimiters. Commented Nov 24, 2019 at 13:35

1 Answer 1

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>";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.