PHP script not working in HTML file

后端 未结 6 2037
北海茫月
北海茫月 2020-11-27 06:22

I\'m new to PHP. I installed XAMPP and have Apache running. I created helloworld.php in XAMPP\'s htdocs and got PHP to display in my browser. My question is, why does my PHP

6条回答
  •  误落风尘
    2020-11-27 06:53

    Too much overkill. All these suggestions lead me down the wrong path for like 5 hours. JK, but I did read a lot of google search items all giving wrong answers and each suggestion was just adding more wrong answers.

    The answer is in fact so simple you would want to bang your head: Simply change the file extension from ".html" to ".php"!!! Remember that you can build a webpage entirely out of PHP and all JavaScript and stuff built off JavaScript like, JQuery, bootstrap, etc will work.

    Here is a simple example of proof:

    
    
        
        
        
    
        Blank Web Page
    
        
    
    
    
    
    
        
    
        

    test to see if this html element can be output too!

    Notice that I am using your standard html, even though it doesn't show my HTML tags(trust me it's there), web page stuff and have php code inserted inside. Of course the result is 15 and the html element h4 renders correctly too. Change the extension back to "html" and you will get only the h4 element and you will find that your php code has been commented out using multi-comment for html.

    I forgot to add that this works for Xampp too.

提交回复
热议问题