.
Tutorial
Avatar

PHP basic lesson 2

By Remco on 2008-11-18
Views: 804

Introduction

As you could see in the previous tutorial, you can display text by using the echo command.
You might already see where this is going, to create a website layout you will need a language like HTML or XTML.
But if you entire file is a PHP file, how can i add HTML or what ever language you prefere to my page?!

In this tutorial we will explain how you can display your website by using PHP.

Step 1


Before we start creating our first HTML page with PHP you will need a PHP file running on the webserver, the name of the file does not matter.

Open the file and make sure you already have the start and end tag in the file:


Code:

<?php

?>




Step 2


Assuming you understand how HTML works we will now echo the basic tags of HTML in the file you just created. This way PHP will write the text to your source code and the browser will see that you are using HTML.
The browser will work exactly the same as if you would be using an HTML file.



Code:

<?php

echo "
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<html>
<head>
     <title>Hello world!</title>
</head>
<body>
Helloo people, this is my first PHP based website!
</body>

</html>"
;

?>


In this code you can see we have created a very basic HTML page which outputs: Helloo people, this is my first PHP based website!
It works like this with all HTML / XHTML you would like to display.

Note

Please note that usually you would use the double quote to describe objects.

Example: style="width:150px;".

If you would do so in PHP, PHP will give you an error!
PHP does so because the double quote tells PHP that the echo is finished with catching the echo's content.
To fix this you will have to use single quotes: '

Example: style='width:150px;'.

Please do not forget this, because loads of people do this by accident.





This was lesson 2, you now understand you can use all sorts of languages like HTML / XTML and many other languages inside your PHP to display your HTML layout.
« Previous Next »




Comments

Sillentkil - 2008-11-18
hey hier kunnen comments Hehe

bij je note, Example: style="width:150px;". beetje raar voorbeeld

Example: echo "<td width=\"5%\">";
Example: echo "<td width='5%'>";

verder leuke tutorialsHappy

Flamer - 2008-11-19
Silentkill moet er ook weer mee bemoeien -.-...zucht.
Anyways, tut klopt helemaal!Happy ik heb trouwens een php scriptje gemaakt wat ook handig is, waar kan ik die uplooijen ??

Remco - 2008-11-19
Flamer, what do you mean ?
What sort of PHP script ? lol i can't just allow people to upload entire PHP scripts due to security risks, but you can always ask me to use scripts in my tutorials Hehe

Send me a mail about it please lol Happy

Sillentkil - 2008-11-19
kon het niet laten maar he je kent meHehe
Maare volgens mij vertrouwd hij ons niet, ons n beetje niks laten plaatsenHappy

ow mooie layout trouwensSmile

Remco - 2008-11-19
lol Hehe ik vertrouw niemand, moet je maar is opzoeken wat mensen kunnen doen al laat je ze toe om scripts te uploaden lol hahaha .. dan kan je alle rechten wijzigen e.d. spullen verwijderen blabla.. niet echt handig he Hehe

Flamer - 2008-11-19
ill send you a pb bout it.

You have to be logged in to write a comment.

.