cameronsch3 Posted July 8, 2018 Share Posted July 8, 2018 Hey, I'm trying to write php in my html page, and this issue always happens, I assume it's just because I have no idea what I'm doing. Here is the code that I wrote. <html> <head> </head> <body> Hello, today is <?php echo date('l, F jS, Y'); ?>. </body> </html> The issue is that whenever the site runs it comments out this code making it this. <html> <head> </head> <body> Hello, today is <!--?php echo date('l, F jS, Y'); ?-->. </body> </html> What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/307465-completely-new-im-not-sure-why-my-code-comments-out/ Share on other sites More sharing options...
benanamen Posted July 8, 2018 Share Posted July 8, 2018 Is the file saved with a .php extension? Are you running the file on a server with Php installed? Quote Link to comment https://forums.phpfreaks.com/topic/307465-completely-new-im-not-sure-why-my-code-comments-out/#findComment-1559394 Share on other sites More sharing options...
cameronsch3 Posted July 8, 2018 Author Share Posted July 8, 2018 @benanamen Hey, So the code I provided was the full .html file, there's nothing more than that, is there supposed to be? Also yes, php is installed on my server. Quote Link to comment https://forums.phpfreaks.com/topic/307465-completely-new-im-not-sure-why-my-code-comments-out/#findComment-1559395 Share on other sites More sharing options...
benanamen Posted July 8, 2018 Share Posted July 8, 2018 Did you not read what I said about having a .php extension? A .html extension is your problem. Quote Link to comment https://forums.phpfreaks.com/topic/307465-completely-new-im-not-sure-why-my-code-comments-out/#findComment-1559396 Share on other sites More sharing options...
cameronsch3 Posted July 8, 2018 Author Share Posted July 8, 2018 @benanamen Thanks! So All I have to do is have the page as .php rather than .html and everything html related will still work aswell as all of the php stuff? Quote Link to comment https://forums.phpfreaks.com/topic/307465-completely-new-im-not-sure-why-my-code-comments-out/#findComment-1559397 Share on other sites More sharing options...
benanamen Posted July 8, 2018 Share Posted July 8, 2018 How about just trying it? But yes. Quote Link to comment https://forums.phpfreaks.com/topic/307465-completely-new-im-not-sure-why-my-code-comments-out/#findComment-1559398 Share on other sites More sharing options...
ginerjm Posted July 8, 2018 Share Posted July 8, 2018 You should format your script (cause that's what it is, not a 'page') like this: <?php // all your php code follows including turning on php error checking php statement; php statement; php statement; // no more php code now // For your output of your html code you could use a block of echo statements // of you could just leave php mode and output raw html only // or you could use the php heredocs statement like this $html =<<<heredocs (all of your html code along with any php vars that you want embedded in the web page) heredocs; echo $html; That is what a proper script should try to look like. Quote Link to comment https://forums.phpfreaks.com/topic/307465-completely-new-im-not-sure-why-my-code-comments-out/#findComment-1559444 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.