PHP Workshop #1: The Basics
PHP Workshop #1: The Basics
Index
- Editors used to code Php
- Simple syntax and coding
- Simple functions
- Your first script
Editors used to code in PHP :
First... welcome to the first part of my tutorial. The basics! Normally we use the windows-notepad but there are a lot of better editors for professional coders. Normally I use UltraEdit-32 for PHP coding because of the code-highlighting but we are going to use the normal windows-notepad in this tutorial. To start coding just open a new notepad session.
Simple syntax and coding :
We always always start php-code with
and end it with
This means not there cannot be HTML code before this <?php , it must not be at the top of your script.
You can also do code like this (look below) but the file ending must be .php because the interpreter (PHP) only recognizes code in .php files.
<?php echo("This is PHP Code"); ?>
<b>This is HTML Code</B>
Maybe you are a bit confused because of the echo(); function right now but I am going to explain it now.
Usage: echo("this is a test");
What it does: It prints out a message, you may use html code within this function like:
echo("<b>this is a test<b>");
But attention: All HTML Codes with "" like <p align="center"> have to be changed to <p align='center'> in order not to get an error.
Maybe this sounds like chinese (if you know chinese... bad luck... think of another language) for you but I am sure you will understand it as soon we try this.
Okay .. now we talk about comments in scripts. I will be using them a lot to make it easier for you to understand PHP.
This is a comment:
echo("Hello"); // This is a comment which explains php to you
?>
You see that a comment starts with //
There are other ways to comment code but i am going to use this way.
I think you are ready to create your first script.l
The first script :
Okay.. what we are going to do is creating a simple script which prints out a bold message. The script lines will be commented.
Lets start:
// This is my first script
// Copyright 2006 by fillnameinhere
// lets start
echo("<b>Hello World. This is my first application</b>"); //Echo Function printing out a message
// End of Script
?>
Wasnt hard, was it?
I hope you enjoyed the first of many PHP workshops by Atira. In the next workshop we will talk about Variables, Arrays and more complicated scripts.
Homework :
Create a script which prints out underlined message (<u></u>) and comment your actions. Post that script in code tags at BitForward. Dont use the script we made above.
Good Links :
The best PHP site out there...
Check if your scripts work
Last Words :
Thanks for taking time to read my guide. Dont give PHP up, it isnt that hard. Make sure you check PHP.NET too, great site with manual and everything.
Yours sincerely,
lilMahsta
Credits 'n' Copyright
Tutorial Copyright 2006 by lilMahsta (Mr. Mandrake) .
Lesson 2: