1

(Edit: Sure you can find the answer on the other question (SOMEWHERE), but it's not exactly duplicate. My situation is different.)

I'm totally beginner level in PHP. This code in my "test.html" is for me absolutely straight-forward:

<html>
    <body bgcolor="ffff00">
    <?php
        echo '<hr>hello world<hr>';
    ?>  
    </body>
</html>

I get this page:

enter image description here

This isn't the first time I had this issue. Last time I solved it and now I don't know how. Why is it printing me the closing apostrophe and semicolon and the closing php-tag-end? What am I doing wrong?

Bitterblue
  • 13,162
  • 17
  • 86
  • 124
  • 3
    PHP isn't running. if you view the source you'll likely see `` – IsThisJavascript May 31 '18 at 15:05
  • 2
    Sorry I just saw that your file is `.html` for it to run php code it must be a `.php` file – IsThisJavascript May 31 '18 at 15:06
  • 1
    The cause of what @IsThisJavascript correctly pointed out simply is: you named your file ``test.html``, but usually http servers are configured such that they only execute php if the file name ends in ``*.php``. – arkascha May 31 '18 at 15:07
  • 1
    Indeed. This may just be because you've called the file `test.html` rather than `test.php`, but there could be other reasons why your PHP interpreter isn't actually running at all... You need to be running your code through a web server with a PHP interpreter configured. – Matt Gibson May 31 '18 at 15:07
  • Wow. What is wrong with stack? How is the question bad? Is it too noobish for you? – Bitterblue May 31 '18 at 15:10
  • 1
    I get the feeling some people try to make SO a place for "experts" by downvoting simple questions. So have an upvote from me; you gave details, and I believe questions like this are helpful to others. – Beofett May 31 '18 at 15:14
  • 1
    I didn't downvote but you probably got downvoted because it's a duplicate. The question was asked in a good manner following the MVCE tho so I wouldn't say a downvote is warranted but a close flag for sure. – IsThisJavascript May 31 '18 at 15:15

1 Answers1

3

You should save the file as .php not .html if you have php code.

kkica
  • 4,034
  • 1
  • 20
  • 40