Php: echo vs include html file

847

In a php script: -What is the difference between

echo "<p>info</p>"

and simply writting html content (what include "htmlfile" basically does)?

include "file.html"

Observation: I read that echo sends a command to web server to send http response, while including a html file waits till the processing php code is done.

In the latter case, does the php module "echoes" at the end of the processing all the html that was written in the php file?

Thank you!

578

Answer

Solution:

Here is what I realised:

  1. A php engine does the following:

-takes the php file

-if it encounters html tags (outside any php tag), it sends to output buffer

-if it encounters php tags, it execute php code inside.

  1. Include file.html statement does the same thing as above, with the observation that all code is analysed sequentially, from top to bottom. From here it comes the misunderstanding that include statements actually copy paste code. No. It involves a mechanism of analysing and/or executing.
  2. Echo sends directly to output buffer
  3. You can't have html tags directly inside php tags.

I hope this can be helping for you in case you have wonders like mine.

People are also looking for solutions to the problem: php - Call to undefined function imagecreatefrompng()

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.