Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP or HTML first or does it matter?

I have a possible stupid question, but I'll ask it anyway.

Does it matter what goes first, PHP or HTML code?

For example: Does PHP go before HTML, after HTML or does it matter at all?

<?php

echo "This is text";

?>


<html>
<head>
</head>
<body>
<center>
<font size="2">This is text</font>
</center>
</body>
</html>

Or:

<html>
<head>
</head>
<body>
<center>
<font size="2">This is text</font>
</center>
</body>
</html>

<?php

echo "This is text";

?>

Or:

<html>
<head>
</head>
<body>

<?php

echo "This is text";

?>

</body>
</html>
like image 590
Funk Forty Niner Avatar asked May 31 '12 04:05

Funk Forty Niner


2 Answers

The third one is the correct way (assuming you want the text to echo out in the body).

PHP can jump in and out of HTML as you have shown above.

<html>
<head>
</head>
<body>
<center>
<font size="2"><?php echo "This is text"; ?></font>
</center>
</body>
</html>
like image 93
Microsis Avatar answered Oct 22 '22 08:10

Microsis


Personally I put the PHP as much as possible at the top of the page or even better outside the html page completely by using the html pages as purely views in the MVC pattern.

like image 35
Chris Avatar answered Oct 22 '22 08:10

Chris