user8202693
user8202693

Reputation: 159

echo HTML with php variable

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

Upvotes: 2

Views: 11977

Answers (3)

Gyan
Gyan

Reputation: 508

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>

Upvotes: 0

ZeroOne
ZeroOne

Reputation: 9117

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>

Upvotes: 1

rahul patel
rahul patel

Reputation: 362

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>

Upvotes: 0

Related Questions