Formatar um Parágrafo utilizando o valor de uma variável estática PHP
Boa noite. Estou estudo POO com PHP e fiz uma classe Pen.php. Inclui um echo com parágrafo nesse código que gostaria de alterar a cor da fonte de acordo com o atributo color da caneta. Pesquisei no Google e sugeriram fazer um arquivo php com as formatações, mas não obtive sucesso. Estou utilizando Apache como server local, última versão disponível do XAMPP. Mesma coisa para a versão do PHP. Segue o código dos arquivos: index.php <!DOCTYPE html>
<html> <head> <meta charset="UTF-8"> <link rel="stylesheet" type="text/css" media="screen" href="style.php" /> <title>POO Lesson 02</title> </head> <body> <div> <label id="model"></label> </div> <?php require_once 'Pen.php'. $c1 = new Pen(). $c1->model = "bic". $c1->color = "blue". $c1->charge = 80. $c1->tip = 0.5. $c1->capped = false. $c2 = new Pen(). $c2->model = "faber-castell". $c2->color = "red". $c2->charge = 50. $c2->tip = 0.75. $c2->capped = true. print_r($c1). echo "<br>". print_r($c2). $c1->scribble(). $c2->scribble().?> </body>
</html> **Pen.php** <?php class Pen { var $model. var $color. var $tip. var $charge. var $capped. function scribble(){ if($this->capped == true){ echo "<p>ERROR! The pen ".$this->model." ".$this->color." is capped!</p>". } else{ if($this->color=="blue"){ echo "<p style='color: blue. '>I'm scribbling with the pen ".$this->model." ".$this->color."...</p>". } else{ echo "<p id='c2'>I'm scribbling with the pen ".$this->model." ".$this->color."...</p>". } } } function cap(){ if($this->capped == true){ echo "<p>ERROR! The pen ".$this->model." ".$this->color." is already capped!</p>". } else{ $this->capped = true. echo "<p>The pen ".$this->model." ".$this->color." is capped!</p>". } } function uncap(){ if($this->capped == false){ echo "<p>ERROR! The pen ".$this->model." ".$this->color." is already uncapped!</p>". } else{ $this->capped = false. echo "<p>The pen ".$this->model." ".$this->color." is uncapped!</p>". } }
} **style.php** <?php header("Content-type: text/css. charset: UTF-8"). require_once 'Pen.php'. $c0 = new Pen(). $color = $c0->color.?> c2 { color: <?php echo $color.?>. }
<?php header("Content-type: text/css. charset: UTF-8"). require_once 'Pen.php'. $c0 = new Pen(). $color = $c0->color.?> c2 { color: <?php echo $color.?>. }Discussão (2)
Carregando comentários...