1

I am trying to program in PHP, but php tags are not working: and i believe there's no error in my code below:

<html>
    <head>
        <?php 
            $test = "Gumagana ako :P";
            echo "$test";
        ?>
        <title>My First PHP</title>
    </head>
    <body>
        My Test String is <?php echo $test; ">
    </body>
</html>

What do you think is the problem? FYI, I'm using xampp.

4
  • where are you running this? did u install a local php server to try that out? Commented Jul 16, 2012 at 12:03
  • 1
    you have to add closing tag ?> like My Test String is <?php echo $test; ?> Commented Jul 16, 2012 at 12:04
  • 10 questions with no accepted answers isn't good. Please go back over your other questions and accept any answers that helped you. Commented Jul 16, 2012 at 12:13
  • @Onheiron yes I have a local php server apache. Commented Jul 16, 2012 at 12:56

6 Answers 6

4

Make sure your file extension is .php and its inside your htdocs folder of Xampp folder. And also make sure, Apache service is running fine.

And also make sure, you are browsing this like http://localhost/yourfile.php

<html>
    <head>
        <?php 
            $test = "Gumagana ako :P";
            echo "$test";
        ?>
        <title>My First PHP</title>
    </head>
    <body>
        My Test String is <?php echo $test; ?>
    </body>
</html>
Sign up to request clarification or add additional context in comments.

3 Comments

Yes I modified my index.php and still my test string is not showing.
@bEtTyBarnes so what was the problem? if it is not solved then why have you accepted the answer??
Make sure your Apache service is running fine. Also make sure, you have changed the extension but not renamed the file name. Are you sure its file name is not index.php.html
3

You made a typo in closing your php.

My Test String is <?php echo $test; ">

Close your php like this:

My Test String is <?php echo $test; ?>

Otherwise php tries to interpret the following as php which gives an error:

"> </body> </html>

2 Comments

Yes I changed it now. But i still got no string output on my website.
the php you asked for is valid, it has something to do with your server configuration check your error log with the terminal/commandline tail -f /var/log/apache2/error.log
1

There is a missing PHP closing tag or the question has been replaced with a double quote :

 My Test String is <?php echo $test; ?>

Comments

1
  <body>


       My Test String is <?php echo $test; ">


  </body>

there is misteck

My Test String is <?php echo $test; ?>

please check it

1 Comment

I changed it now. But only blank space displayed
1

Just Write like this : -

My Test String is <?php echo $test;?>

4 Comments

I changed it now. It still is the same.
can u tell me what u want to do ??
I want to view My Test String Gumagana ako :P
<body> $test="abc"; My Test String is <?php echo $test; ?> </body>
1

My Test String is <?php echo $test; ?> //tag was not closed

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.