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?
3 Answers 3
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.
5 Comments
<?php echo part is not printed out on the screen?http://localhost/...)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.phpthen 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
Comments
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.
echo??and check again and see what it outputs. Mean the?after Hello. Maybe it is closing your php tag or something