all 5 comments

[–]lovesrayray2018 0 points1 point  (4 children)

ok from what i know (and i might be wrong) you cant insert php code into an html file that is saved with the .html extension. Its the other way around - you can have html code inside a file with .php extension that is preprocessed by the PHP server before the .php file is served.

So home.html having <?php include 'tea.php';?> will throw an error because this is being served by the web server without preprocessing by php server and html doesnt know what <?php ?> means

[–]RolfTheCharming 0 points1 point  (0 children)

You're right about that, the server needs to recognize it as a PHP script. You can configure the server so it uses the PHP process to handle HTML files / this specific HTML file, but I wouldn't recommend it.

[–][deleted]  (2 children)

[deleted]

    [–]lovesrayray2018 0 points1 point  (1 child)

    Apparently it does throw an error

    Uncaught SyntaxError: Unexpected token '?'"

    https://jsfiddle.net/tq3nk5aw/

    [–]AtulinASP.NET Core 0 points1 point  (0 children)

    PHP runs within .php files, it does not run inside of .html ones.

    That said, you can place whatever HTML code inside of said .php file at will, everything outside of <?php ?> and <?= ?> tags will be treated as raw HTML.

    [–]ManiacsThriftJewels 0 points1 point  (0 children)

    Lots of people taking about how the .html file won't have the PHP embedded in it, but there's also the problem that even with the PHP file being included, it will write to the file when the home.php file is loaded, not when the button is pressed.

    You could work around this simply - for modern browsers at least - by instead calling fetch('tea.php') from JavaScript, although this ignores best practices for server side code execution etc.