Freedom The Open Source Way Contribute Articles or News to OSForgeOSForge HomeLogout from Forums
Contacting OSForgeOSForge HomeAbout OSForge
  

Root
Contribute News
Learning Corner
Linux Distributions
Linux Common FAQ's
Discussion Forums
Community Gallery
Links Directory
Search OSForge
Networking
Industry Updates
Linux & Open Source
Opinions
Press Release
Programming
Security
Web Development

White Paper
DAKCS Software Systems Introduces Innovative Customer Training Program
Zarafa and ClearCenter Announce ClearOS Integration
Zarafa Brings Browser-Based Enterprise Collaboration Client to CeBIT
Zarafa Catalyses Software Development Collaboration by Launching git.zarafa.com
Zarafa and LPI Partner on Training and Certification Program
Likewise to Grow Seattle-Area Workforce
Likewise CTO: Unleash and Secure Unstructured Data
Likewise Names Leading Open Source Voice as CTO
Launched: Zarafa Collaboration Platform 7.0 and Zarafa Archiver

View More »

The Basic of PHP
By : Ewdison Then Find more article by Ewdison Then on Program
Wednesday the 22nd, May 2002 at 12:17 PM (EDT)
Send this Story to a Friend Readers TalkBack (0) - 4796 Reads

Printer Friendly Page Printable format
Send this Story to a Friend Foward to Email

PHP stands for the Hypertext Preprocessor. PHP is embedded in HTML files and is extremely easy to learn and code. PHP is a server side scripting language, that is, the server processes the PHP code and sends the output to you. Thus, it is not possible to view the source of the PHP code. PHP code cannot be run on your computer unless you are running a server, download PHP Triad so you can test your PHP code on your computer.

PHP syntax is very much familiar to C/C++ syntax and should be easy to pick up if you have a sound background in C or C++. PHP code can be included anywhere in your web-page, much like Javascript. Now, let us make our first PHP page which displays the customary "Hello World" text. First, you must know that all PHP code must be included between <? and ?> tags. The basic function to print text to the screen is ECHO even though there are other functions such as printf which we will discuss later on. Here is the code for our first PHP page ?

<HTML>

<HEAD>

<TITLE> My first PHP program! </TITLE>

</HEAD>

<BODY>

<?

Echo "Hello World!";

?>

<BODY>

</HTML>

Nearly all PHP commands end with a ; except "if", "for" and some other functions, just like in C. Remember the text you want to be printed must be included between the " and he ". An article I read states that it is better to use <?php instead of only <? Because languages like XML may confuse <? with one of their tags. Now, let us learn how to use variables, they do not have to be declared, just like in BASIC and Perl. Variables in PHP begin with a $ sign, for example $nikhil. Variables in PHP are of a single type, unlike in C or other languages, that means you can store both numbers and characters in a variable. This is how you create a variable ?

$nikhil = "Hello Nikhil";

Lets integrate this into our page ?

<HEAD>

<TITLE> My first PHP program! </TITLE>

</HEAD>

<BODY>

<?

$nikhil = "Hello Nikhil";

$number = 350;

Echo $nikhil;

Echo $number;

?>

<BODY>

</HTML>

Nice huh? The output of this program would be "Hello Nikhil350". Note, that there is no need to use "" when assigning integer values to a variable. Remember that variables in PHP are case-sensitive, that means, $nikhil and $NIKHIL are completely different. Now lets learn how to do some basic math in PHP. Firstly to add we use +, to subtract we use -, to divide we use /, to multiply we use *. We will now create a page which demonstrates all of these functions ?

<HEAD>

<TITLE> My first PHP program! </TITLE>

</HEAD>

<BODY>

<?

$one = 4;

$two = 2;

echo one + two;

echo "<br>";

echo one - two;

echo "<br>";

echo one * two;

echo "<br>";

echo one / two;

echo "<br>";

?>

<BODY>

</HTML>

The echo "<br"> line makes PHP leave a line. Notice that if I used -

echo "one + two<br>";

The output would be "one + two" and not the number six. The final output of the page we coded above will be ?

6

2

8

2

That?s all for The Basics of PHP, watch out though, I?ll be writing another tutorial on PHP which will discuss Loops, Files and Advanced Math

  
Reader Rating from 1-5

 

Poor very 

1

2

3

4

5
 very Excellent

Talkback

Post Your Talkback | View All Talkback (0 Posted)


 Currently there are no Talkback posted on "The Basic of PHP", Click here to be the first to post a talkback.


 
Scroll Up

   About | Term of Use | Privacy | Contact us | Tell a Friend | Advertise  

OSForge News RSS Feed