Computersight > Programming > PHP

The Basics of PHP

Programming in PHP can be complicated at first. Learning the basics of PHP can be easy.

Comments

Comments are very simple, they are defined using //

For example:
// My Comment

Multi-line comments can easily be defined by using /* and closing with */

For example:
/* My Comment 1
My Comment 2
My Comment 3 */

Outputting Text

Output text with PHP is easy. There are also several ways to output text. The simplest way to output text is to use the echo function.

For example:
echo “Example of echo function”;

Variables

Defining variables in PHP is fairly simple.

For example, a simple variable would look like:
$myvar = “My Variable”;

To use a variable, simple use the variable name that you defined, for example:
echo $myvar;

Global Variables

There are pre-defined global variables, such as $_SERVER.

An example outputting a visitor's IP using $_SERVER:
echo $_SERVER['REMOTE_ADDR']; // This outputs the visitor's IP address.

Arrays

Arrays are defined by using the array() function

For example:
$myarray = array(“Array1”, “Array2”);

To use an array:
$myarray['Array1'] = “My Array”;
echo $myarray['Array1'];

2
Liked It
I Like It!
Related Articles
What is PHP? Learn the Basics  |  PHP Tutorial: Printing on the Screen
More Articles by Kramer
How to Use SSH as a Proxy
Latest Articles in PHP
What is PHP? Learn the Basics  |  PHP Tutorial: Printing on the Screen
Comments (0)
Post Your Comment:
Name:  
Copy the code into this box:  
Post comment with your Triond credentials?
Inside Computersight

Communication & Networks

 /

Computers

 /

Hardware

 /

Operating Systems

 /

Programming

 /

Software


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

© 2007 Copyright Stanza Ltd. All Rights Reserved.