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? Link to comment 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? Link to comment 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. Link to comment 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. Link to comment 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? Link to comment Share on other sites More sharing options...
benanamen Posted July 8, 2018 Share Posted July 8, 2018 How about just trying it? But yes. Link to comment 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.