Jump to content

Completely new, I'm not sure why my code comments out.


cameronsch3

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.