Computersight > Programming > PHP

PHP Tutorial: Printing on the Screen

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.

Step 1:

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.

Step 2:

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:

  1. print ( “ your output ” ) ;
  2. print “ your output ” ;
  3. echo “ your output ” ;
  4. 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.

12
Liked It
I Like It!
Related Articles
PHP Founders Forget Hebrew Error Messages Within PHP Core  |  PHP's Benefits
More Articles by lonely
How to Draw an Oblique Cone
Latest Articles in PHP
The Basics of PHP  |  PHP: Learn by Doing, Learn Faster by Breaking
Comments (1)
#1 by Jared Stenzel, Apr 22, 2008
I'm actually trying to learn php. I've been reading a book for the last month or so trying to learn it.
Post Your Comment:
Name:  
Copy the code into this box:  
Inside Computersight

Communication & Networks

 /

Computers

 /

Hardware

 /

Operating Systems

 /

Programming

 /

Software


Popular Tags
Popular Writers
Computersight
About Us
Terms of Use
Privacy Policy
Services
Submit an Article
Advertise with Us
Contact

© 2007 Copyright Stanza Ltd. All Rights Reserved.