Starting out - tags - echo - nothing works without HTML - but how does PHP work?
Topics

--><!-- Nothing works without HTML -->


<div>

<h1 itemprop="headline">Starting out - tags - echo - nothing works without HTML - but how does PHP work?</h1>


<img src="../images_July_2015/container.jpg" width="300" height="407" alt="" />

<h6>There's a button below (sneak peek) to peek at the code.</h6>



<p>
Starting from here, I'd like to remind you of the button "Sneak peek of the server side code" below.
We are going to need this one. In my text editor the main content of this paragraph consists of a
few lines, inside a p-element (paragraph). The text is in-between &lt;p&gt; and &lt;/p&gt;. This
is the one element you as a writer are going to be using most of the time. Press
"Sneak peek of the server side code" now and look
at the code and how that which is visualized is visualized by the browser.
</p>



<p>
So what you see in the window, is what the browser creates out of the text that is located inside the p-element.
</p>

<p>
This code is stored somewhere on a server somewhere. I don't know the exact location of the server and I don't have to, but I know
the code is a physical instance, it is substantial. It is sent to the browser by the server, having been requested by you, the
user.
</p>

<p>Note the file ending in the URL at the top. It is php, and not html. Why is this so? What is actually happening is,
we are telling our server: "Look here, buddy, this page is not pure html, there is some php-code mixed in. Before you send it to
the user make sure you execute the php-code first.</p>


<p>And this is what is happening. The server executes php-code such as this: (press "sneak peak" button to view php-code)</p>

<div>Php says:</div>


<?php
$variable = "sugar";
echo "<p>$variable</p>";
?>



<p>What is happening now? There is a program on my server, the php-interpreter, it is told that it needs to create a container, into
which something can be put. At the same time you are telling the interpreter that the content of the container, named $variable, should be "sugar".
The echo command tells the interpreter to send the p-tags and the content of the variable, which is
"sugar", to the browser. This will output <i>sugar</i> Remember that each command is seperated by a semicolon (;).</p>



<p>
You can then put something else into our container:
</p>

<div>Php says:</div>

<?php
echo "\n";//creates a new line


$variable = "vanilla";
echo "<p>";
echo $variable;
echo "</p>";

echo "\n";//creates a new line
echo "\n";//another new line
echo "\n";
?>
<p>That is why it is called a variable. Because you can change its content. The content is "variable" or interchangeable.</p>
<p>
Note the &lt;?php at the beginning and ?&gt; at the end. These tags are the php-tags, telling the interpreter, hey dude, this is where in-between
you will find php-code, do please execute it now.
</p>


<p>From what we have talked about, I hope that you get that there are two types of code. One on the server (which is displayed by
pressing the "sneak peek" button) and the other being that which the browser receives from the server:</p>

<div>
<img src="../images_July_2015/php_1_code.png" width="245" height="128" alt="source code" />
</div>
<p>
This is a screenshot of the code behind the site that you get if you right-click on the page (not on the image) and chose "show source" like this:
</p>
<div>
<img src="../images_July_2015/php_1_show_source.png" width="250" height="223" alt="how to show the source code in browser" />
</div>
<p>So now, do you see the difference between this:</p>
<?php
echo "\n";//creates a new line
echo "\n";//another new line
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
?>
and this?
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<p>Note the distance between the paragraphs. Looking at the page, 'echo "\n";' makes no difference, but &lt;br/&gt; does.</p>


<p>Now looking at the code, you will see that the browser receives 'echo "\n";' and that it does make a difference:</p>


<p>
<img src="../images_July_2015/php_1_code2.png" width="546" height="705" alt="code" />
</p>


<p>
Thing is, you don't see it HERE, because the new lines are only generated in the code that the browser receives and
all browsers do the same to whitespaces and new lines, they ignore them.
</p>

<br/>
<br/>
<br/>



<a href="http://www.primitivecode.com/index.php?topic=-PHP-single+and+double+quotes-in+php-difference-">
&gt;&gt; continue</a>
<br/>

<br/>

<br/>
<br/>
<br/>
<?php $Weblog->share ();?>


<br/>
<br/>
<br/>
</div>

Sneak peek of the server side code