include vs file_get_contents what is the difference?
Topics

include and file_get_contents

I use this file:

hello_world.php/hello_world.txt

When you request a file by relative paths (not http://www.page_xy.com/path/to/your/stuff/stuff.html) file_get_contents gets text, plain and simple. But if you request a file by using http://www.page_xy.com/path/to/your/stuff/stuff.html it gets preprocessed and php is executed. Take a peek at the code by clicking below.


Hello world!
HTML-Code

Hello world!
HTML-Code
*********************** -1- *************************
string(51) "
HTML-Code
"
---
string(51) "
HTML-Code
"
---
string(32) "Hello world!
HTML-Code
"
---
string(51) "
HTML-Code
"
*********************** -2- *************************
HTML-Code
---
HTML-Code
---
Hello world!
HTML-Code
---
HTML-Code
*********************** -3- *************************
<?php echo ("Hello world!");?> <div>HTML-Code</div>
<?php echo ("Hello world!");?> <div>HTML-Code</div>
Hello world!<div>HTML-Code</div>
<?php echo ("Hello world!");?> <div>HTML-Code</div>

I find this is really interesting stuff. To look at it with the help of such simple code is very enlightening as to the role of php, that is the relationship between server and client. One has to always keep in mind, that there are three types of text involved in expression of code.

  1. The server side code
  2. The client side code
  3. The actual text the user gets to see

On the server side php processes the code. The created code goes to the browser. It then gets processed again by the browser. This is the code how the browser receives it, and then we find the reason why certain elements are not displayed, the reason being that the browser doesn't know what to do with php-tags.






submit to reddit





Sneak peek of the server side code