Helping you to understand the basic of PHP scripting language. This may be your first step to the mysterious world PHP.
PHP is a script language commonly used by webmasters to design dynamic websites. Unlike HTML which has static content, PHP has dynamic content because of user interaction. Today, most of the qualified websites are designed by PHP or CGI.
PHP scripts embedded into the HTML codes. When someone checks the source code of the page, he doesn’t get anything about PHP scripts. He only learns the HTML part of coding. This article is an introduction to PHP scripting language. One can find useful information and have enough knowledge after reading my PHP tutorial series. Without delay, I would like to start my script creation step by step.
Before starting, you should know that you have to set up PHP installations into your computer. Such installations are PHP itself, Phpmyadmin interface, Mysql database and Apache Server. Without these, your scripts are nothing since they are not compiled by your computer.
To write PHP scripts, we need a place. That place is a simple text editor. You are free to choose your text editor. I prefer to use Notepad. There are other alternatives like Editplus or Elfima. If your operating system is not Windows but Linux, you can place your code into Vi editor or Pico. I have never tried but I think you can use Dreamveawer, Hotdog or Frontpage.
In your text editor, open an new file and save it as “myfirst.php” or “myfirst.html” . I choose the name of file as “myfirst” but you are free to choose anything.
I have told you before that PHP scripts are embedded into HTML codes. So, first of all we will write HTML codes. The basic codes are HTML, TITLE, HEAD and BODY. It can be written by lowercase letters as well. This part is not important.
Step 3: All PHP scripts start with “ ”. Only the part between two is compiled by server and evaluated as output.To print characters on the screen, standart output functions of PHP are used. Those are “ print ” and “ echo ”. In some circumstances, ” printf ” is used too.
The format of printing:
- print ( “ your output ” ) ;
- print “ your output ” ;
- echo “ your output ” ;
- echo ( “ your outpu t” ) ;
If you don’t use any white space characters, the strings are written without any separation. For example if you write this code;
- Print ( “ Word1 ” ) ;
- Print ( “ Word2 ” ) ;
It will be outputted as Word1Word2.
To remove this fault,white space characters are used. In PHP code part, between print functions, we place < br > code.
Example: To be more understandable,I will write a simple PHP script. Output will be the name of my favorite Triond writers.
To see the output, Click here.