2

I'm trying to display the following and I have a css code for it but it doesn't work. Any help would be appreciated.

HTML/PHP

 $var = "Hello World";
    echo '<p>' . 'the value of the variable is : ' . $var . '</p>';

CSS

p
{
    text-align: center;
    color: red;
}

Thanks for your help

10
  • So, what do you see on the page? Commented Jul 5, 2017 at 6:14
  • @u_mulder the value of the variable is : Hello World but in black and aligned to left ( Note what I see is not in bold, I just did it in this comment ) Commented Jul 5, 2017 at 6:15
  • Check with developer tools what styles are applied. Commented Jul 5, 2017 at 6:16
  • Then the PHP works, how do you add the CSS? btw, instead of echoing html you could stop php execution and echo php variables inside html instead. ie $var = "Hello World"; ?> <p>the value of the variable is : <?= $var ?></p> Commented Jul 5, 2017 at 6:17
  • How did you implement your CSS into your Page? Commented Jul 5, 2017 at 6:18

3 Answers 3

1

Try this.. run in your php enviroment

<html>
    <head>
         <style type="text/css">
           p
           {
              text-align: center;
              color: red;
           }
        </style>
    </head>
    <body>
    <?php
      $var = "Hello World";
      echo "<p>The value of the variable is : " . $var . "</p>";
    ?>
    </body>    

</html>
Sign up to request clarification or add additional context in comments.

Comments

0

Its working for me in localhost.

  <?php
    $var = "Hello World";
        echo '<p>' . 'the value of the variable is : ' . $var . '</p>';
    ?>
    <style type="text/css">
    p
    {
        text-align: center;
        color: red;
    }
    </style>

Comments

0

Use as below

<?php 
$var = "Hello World";
echo "<p>The value of the variable is : " . $var . "</p>";
?>

Or like below in your HTML code where you want the php variable

<p>The value of the variable is : <?php echo $var;?></p>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.