Sam Ofloinn
Sam Ofloinn

Reputation: 113

PHP code not outputting properly

I'm working with PHP and HTML, but I have an issue popping up whenever I write some PHP code. An example of this is as follows:

<?php
echo "<h2>Hello?</h2>";
$var = 5;
echo "You have $var minutes to go.";
?>

What this ends up outputting on screen is:

Hello?"; $var = 5; echo "You have $var minutes to go."; ?>

But what I want to happen is this: Hello? You have 5 minutes to go.

Is there something I'm forgetting to do? It doesn't seem to matter whether or not I add the HTML preamble, or if I put a tag like

around the second echo line. Does anyone have any advice?

EDIT: Apparently I have failed to parse PHP correctly. This computer is new and I have XAMPP installed on it, but nothing else. Did I miss something I needed in order to use PHP?

Upvotes: 2

Views: 101

Answers (3)

MonkeyZeus
MonkeyZeus

Reputation: 20737

The PHP isn't being parsed properly.

  • Make sure you are saving your files as .php
  • If you are running this locally through WAMP the make sure to use localhost in your URL because if your URL looks like this file:///C:/wamp/www/index.php then that is incorrect.
  • I think CakePHP uses .ctp files so that could also be an issue
  • You can setup Apache to interpret any file extension as PHP

Upvotes: 2

DS9
DS9

Reputation: 3033

make php and html different.so things become much easier. try like this:

<h2>Hello?</h2>
<?php
$var = 5;
?>
You have <?php echo $var;?> minutes to go.

Upvotes: 0

bwoebi
bwoebi

Reputation: 23777

That sounds like if the php code wasn't interpreted.

Make sure to have the code in a file with a filename ending with .php and that PHP is installed/enabled on your server.

Upvotes: 6

Related Questions