Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Getting Started with PHP Web Development

In this article we will learn php from the very beginning. We will take a complete look of some properties in this web language.

Introduction

First of all we will see the requirements for php programing i.e XAMPP control panel installation, how to write code in dreamweaver, and how to show output of your code in a browser directly without entering URL of your page manually. After that when you are able of the development environment of php we will start from the very basic of php i.e syntax for php, how to write comments in code, variable & data types, casting ,operators and constants.

For practicing php, the following are required:

  • Server software i.e windows xp or Linux.
  • A php compatible web server i.e Apache.
  • Php 5.
  • Mysql server
  • A php editor i.e php designer 2008 or dream weaver.
  • Web browser (Mozila firefox, Explorer).

A complete development package in the form of XAMPP is available, which provide a development environment for a web developer. XAMPP provide a good configuration and can be installed, configured automatically as a result of which a lot of time is saved.

When we install XAMPP the following things are installed and configured.

  • Apache 2.2.6
  • Mysql 5.0.45
  • PHP 5.2.4 +PHP 4.4.7 +PEAR . (php two versions)
  • PHP -switch win32 1.0.
  • XAMPP control version 2.5.
  • XAMPP Security 1.0.
  • SQLite 2.8.15
  • OpenSSL 0.9.8e
  • phpMyAdmin 2.11.1
  • ADOdb 4.95
  • Mercury Mail Transport System V4.01b
  • FileZilla FTP Server 0.9.23
  • Webalizer 2.01-10
  • Zend Optimizer 3.3.0
  • eAccelerator 0.9.5.2 for PHP 5.2.4

INSTALLATION OF XAMPP

DOWNLOAD the XAMPP, double click and follow the screen shorts.(Although WAMP server can also be used but XAMPP is a complete package compared to WAMP).

Step 1: After double click

starting the xampp

Figure 1: starting the xampp

Step2: Press ok the following message will appear

UAC message

Figure 2: UAC message

Step3: press ok and the screen shot appeared will be

set up wizard

Figure 3: set up wizard

Step4: Enter ‘Next , select destination folder and enter ‘Next’ again.

choosing destination folder for xampp installation

Figure 4: choosing destination folder for xampp installation

Step5: The XAMPP options will be appear, select them according to your requirement and press ‘Install’

shows options for desktop icon, xampp startup menu and other services for installing

Figure 5: shows options for desktop icon, xampp startup menu and other services for installing.

Step6: your installation will starts and following screen will appear

shows your installation started.

Figure 6: shows your installation started.

Step7: The following screen shots will appear press ‘Finish’.

shows XAMPP setup version, an indication of successful installation.

Figure 7: shows XAMPP setup version, an indication of successful installation.

 shows your installation completes.

Figure 8: shows your installation completes.

Step8: finally the successful installation will be shown in following screen and press ‘Yes’ to start XAMPP control panel.

Note: Allow firewall access

command prompt for just showing a message that your mysql service is starting.

Figure 9: command prompt for just showing a message that your mysql service is starting.

shows a message that you can manage services from XAMPP control panel.

Figure 10: shows a message that you can manage services from XAMPP control panel.

Asks for to start XAMPP or not.

Figure 11: Asks for to start XAMPP or not.

Step9: Press ‘No’ to start XAMPP control panel manually as shown below.

When the installation completes a folder with a name XAMPP will be made in C drive. Which will contains different softwares like PHP5, Apache, FileZilla, Mysql, Mercury, PHPMYadmin, etc. To run different services open XAMPP control panel as:

Start->programs->Apache Friends->XAMPP control panel.

You can stop or Start a service from below panel:

xampp control panel showing various services that are running.

Figure 12: xampp control panel showing various services that are running.

Now to write php programs, I used dreamweaver as an editor.

Open dreamweaver, select File->New->PHP and press ‘create’. A new window will be opened like this:

Dreamweaver window showing  code section for writing code.

Figure 13: Dreamweaver window showing code section for writing code.

Write the following code:

Listing 1: practice.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: //www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http: //www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mr.bool</title>
</head>

<body>
<?php
echo"welcome to Mr.bool website";
?>
</body>
</html>

Create a new folder’ website’ in htdocs, then save the code in it with name practice.php.

i.e C->xampp->htdocs->website->practice .php.

Now go to ‘site’ tab in dreamweaver, press ‘New Sites..’ and write name and select folder as shown in figure 11.

shows site setup i.e code file folder

Figure 14: shows site setup i.e code file folder

Then click ‘servers’ as shown in left of figure 11 and click the ‘+’ to add a new server and write the various contents as shown in figure 12 and save it.

shows server name, url, and connection type.

Figure 15: shows server name, url, and connection type.

Now press ‘F12’ or ‘preview/debug in browser’ in dreamweaver to preview your code result as shown in figure.

shows output message in Mozilla browser.

Figure 16: shows output message in Mozilla browser.

Now you are aware of how to write the code and run it, we will move to further concepts of php language.

Basic Syntax of PHP:

When we embed php script in HTML, first we open php tag.

<?php  (use for php open tag)

Then we write php script inside it like:

echo”welcome to mr.bool”; 

With help of echo statement we print a text written inside single quotes (‘ ’) or double quotes (“ ”) on a page.we can also use “print” instead of “echo”.

?> (used at the end to close the tag )

PUTTING COMMENTS IN CODE:

Comments in code are used for clarity and explanation of code and are ignored by php engine.

For one line comment we use a hash (#) or two forward slashes(//) i.e

#this is a comment;
//this is also a comment;

For comments of more than a line we use forward slash and a sterik (/*) and for closing a sterik and a slash(*/) i.e

/* this is not 
 a single line code ,but a multiple line */ 

VARIABLES IN PHP:

Variable are used to hold a data in memory. The concept of variables in php is same as in other programming languages only syntax is changed. In php to write a variable first dollar sign and then name of variable is written.

Syntax:

$a;
$b=8; //variable b is assigned value 8;

DATA TYPE:

PHP is a loosly type language means that we can assign any type of data(double,int,string) to a variable.

Listing 2: TO KNOW DATATYPE OF A VARIABLE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: //www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http: //www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$x;//not declared
echo"The data type of variable $x is: " .gettype($x). "</br>";
$x=5;//integer
echo"The data type of variable $x is: " .gettype($x). "</br>";
$x="mr-bool";//string
echo"The data type of variable $x is: " .gettype($x). "</br>";
$x=78.66;//double
echo"The data type of variable $x is: " .gettype($x). "</br>";
$x=true;//boolean
echo"The data type of variable $x is: " .gettype($x). "</br>";
?>

</body>
</html>
 shows output of listing 2

Figure 17: shows output of listing 2

In the above code “gettype()” is function used for finding datatype of variable. Similarly we can use “settype ()” function to set datatype of a variable. For example

Listing 3: THE USE OF SETYPE() FUNCTION

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: //www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http: //www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>settype</title>
</head>

<body>
<?php
$x=188;
echo"The data type of variable $x is: " .gettype($x). "</br>";
settype($x,"string");
echo"The data type of variable $x is: " .gettype($x). "</br>";
?>

</body>
shows output of listing 3.

Figure 18: shows output of listing 3.

CHANGING DATATYPE WITH HELP OF CASTING:

If we write the datatype of a variable in brackets before the variable , it will change its datatype. The difference between “settype()” and ‘CAST’ is that the cast does not change the original datatype of variable but produce a copy of that variable and change it. For example:

Listing 4: CHANGING DATATYPE BY CAST METHOD

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: //www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http: //www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>settype</title>
</head>

<body>
<?php
echo "The datatype of variable  is changed to various types by casting method</br>";

$x=188;
$y=(double)$x;
echo gettype($y);//double
echo"---$y</br>";
$y=(string)$x;
echo gettype($y);//string
echo"---$y</br>";
$y=(integer)$x;//integer
echo gettype($y);
echo"---$y</br>";
$y=(boolean)$x;//boolean
echo gettype($y);
echo"---$y</br>";

?>

</body>
</html>
shows output of listing 4.

Figure 19: shows output of listing 4.

In the above code we assigned an integer value to variable ‘x’ and changed its datatype to double, string, and Boolean.

In php there are also other functions available to change datatype. For example:

intval(value);  // takes a value and  returns an integer value.
doubleval(value);// takes a value and returns a double value.
strval(value); // takes a value and returns a string value.

WRITING A SPECIAL CHARACTER IN echo OR print STATEMENT:

To write a special character like double quotes(“”),single quotes(‘’),backslash (\) or any other white space character, we use a backslash (\ ) in echo or print and then write that character . For example

Listing 5: TO USE SPECIAL CHARACTERS IN YOUR STATEMENT

<html>
<head>

<title>special character</title>
</head>

<body>
<?php
echo"This is \"Mr-bool\" website";
?>

</body>
</html>
shows output of listing 5.

Figure 20: shows output of listing 5.

OPERATORS IN PHP

The concept of operators in php is same as in other languages i.e arithmetic operators, logical operators, assignment operators, increment decrement operators, except concatenation operator (.) which is used for adding two strings. For example

Listing 6: THE USE OF CONCATENATION OPERATOR(.)

<html>
<head>

<title>concatenation operator</title>
</head>

<body>
<?php
$x=100;
echo"These are" .($x).  "balls";
?>

</body>
</html>
shows output of listing 6

Figure 21: shows output of listing 6

CONSTANTS IN PHP

Constant are used when we want not to change the value of a variable and make it fix throughout the program. Constant is a type of a variable whose value once assigned can’t be changed.

For making constants we use to define a function “define()” in php. In this function we write name of constant and assign a value to it i.e

define(“pi”,”3.14”).

Listing 7: how to declare constants

<html>
<head>

<title>constants</title>
</head>

<body>
<?php
define("pi","3.14");
echo "value of pi is: " .pi;
?>

</body>
</html>
shows output of listing 7

Figure 22: shows output of listing 7

Conclusion:

In this tutorial we learned the installation of xampp, use of dreamweaver , and programming concepts of php like datatypes, casting, operators and use of constants. With these concepts in mind you are able now to make atleast a page and view its result. Now you have concepts in minds practice again and again to make your base strong. We will move further to advanced concepts in our next article. If you have difficulty please mentioned it I will be there to answer.



Software developer doing B.E in Computer Science at Hamdard university karachi. Have good skills in php, html, javascript and css.

What did you think of this post?
Services
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login