PHP or HTML first or does it matter?

I have a possible stupid question, but I’ll ask him anyway.

Does it matter what comes first, PHP or HTML?

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>
+5
source share
6 answers

The third correct way (if you want the text to be reflected in the body).

PHP can enter and exit HTML, as you showed above.

<html>
<head>
</head>
<body>
<center>
<font size="2"><?php echo "This is text"; ?></font>
</center>
</body>
</html>
+5
source

Personally, I put PHP as much as possible at the top of the page or even better outside the html page, making full use of html pages as pure representations in the MVC template.

+3
source

php html.

, , HTTP-, , ..

php html.

html , . , html.

, , .

+3

HTML , PHP , . / HTML-. HTML , PHP . , PHP (), HTML ().

+3

, html. - html. - . , , .

+2

Not being a php person, he will try to understand this in a general sense. HTML for browsers and php for server side. When your pages get to the browser, there is only HTML, and if I'm not mistaken, since php should behave similarly to yo jsp, on serveride html are considered as simple lines that need to be printed in a stream. Therefore, ideally, it does not matter what comes first.

From the point of view of good practice, since this is php code (in my case jsp), the output of which will be html, I am trying to give more java feel to my code file.

+2
source

All Articles