Webhost php not enabled

Hello,

I wanted to run a php script inside a html file. I’m new to php so I don’t know a lot here but I believe that php is not enabled.

The code inside of my html file is as follows:

 
<!doctype html>
< html>
< head>
< meta charset="utf-8">
< title>test PHP</title>

< /head>


< body>

    
         <?php
$color = "red";
echo "My car is " . $color . "<br>";
echo "My house is " . $COLOR . "<br>";
echo "My boat is " . $coLOR . "<br>";
?>
   
< /main>
< /body>
< /html>

Now I believe that the produced view should output:
My car is red.
My house is red.
My boat is red.

instead of getting the supposed output, the following output is the result:

"; echo "My house is " . $COLOR . "
"; echo "My boat is " . $coLOR . "
"; ?>

It would seem to me that php is not enabled. How do I enable php?

Thanks in advance

The code should be like

<?php
$color="red";  //just a simple variable//
echo "My car is " . $color . "<br>";
echo "My house is " . $color . "<br>";
echo "My boat is " . $color. "<br>";
 ?>
1 Like

That is exactly how my code reads :slightly_smiling_face: ( It came out a little out of order in my original post)

Hi @kevpbroderick!

  1. Make sure your file extension is .php

  2. PHP variables are case sensitive. $color is not the same with $COLOR

Please reply if your issue is solved.

Hi teodor,

I changed the file extension to .php and fixed the color variable to be of equal case. This did work correctly producing the correct result (though I had to remove the html syntax) :

My car is red.
My house is red.
My boat is red.

But I though that it was possible to execute php within a html file. Is this not the case?

Your HTML tags were not written correctly. You must not leave spaces between element declaration:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>test PHP</title>

</head>


<body>

    
         <?php
$color = "red";
echo "My car is " . $color . "<br>";
echo "My house is " . $color . "<br>";
echo "My boat is " . $color . "<br>";
?>
   
</main>
</body>
</html>

Ok

Just at the line of <?php the compiler on edit is giving the following error message:

Expected tag name. Got ‘?’ instead. HTML doesn’t support processing instructions.

Ok,

I think that this is finally resolved. HTML can be mixed with php but it must be saved with a .php extension.

Thanks very much to you all.