SlideShare a Scribd company logo
1 of 5
PHP Made Easy by Dr. Perl1




What is PHP?
PHP (recursive acronym for quot;PHP: Hypertext Preprocessorquot;) is a widely-used Open Source general-purpose scripting
language that is especially suited for Web development and can be embedded into HTML.

Simple answer, but what does that mean? An example:

Example: An introductory example

 <html>
    <head>
         <title>Example</title>
    </head>
    <body>
         <?php
         echo quot;Hi, I'm a PHP script!quot;;
         ?>
    </body>
 </html>

The above written quote and example is from PHP's official manual. Let me explain and introduce you with PHP in
some more detail.

Most of us spend a few hours on internet to check/send emails, view/post something to a discussion board (like this
one), to search for some solutions using search engines, do some orkut or facebook. But a few of us will ever realize
that what has made these sites so powerful, intelligent and self-maintaining?

Very simple answer to this question is: Web Application Development Technologies.

Don't get afraid of this heavy words term - it's all about the techniques and how you use 'em. Another simple answer
would be the, PHP, ASP (Active Server Pages), JSP(Java Server Pages), CFM (Cold Fusion Markup Language) or PERL
(Practical Extraction and Reporting Language). These are most renowned web scripting languages and are widely
used to develop (or simply program) a website to register users, allow them to post topics, view topics, chat with
friends and etc etc.

In this series (PHP Made Easy by Dr. Perl) I will introduce you to the PHP, what it can do and how you can benefit
from PHP?

You can use PHP to:

    •    Print current date and time on your website.

    •    Print greetings to your visitors based on time, like Good Morning, Good Noon and etc.

    •    Ask comments about your article.

    •    Offer subscription to your weekly news letter.
             drperl@hotmail.com
PHP Made Easy by Dr. Perl2



    •    Register visitors to enjoy member services.

    •    Enable your website to accept online payments, via Credit Cards, PayPal and etc.

    •    Keep track of daily visits on your website.

    •    Collect statistical data from daily visits, to find out that how long a user stayed on your website and which
         pages were browsed mostly and likewise.

    •    Administer your website remotely, so that you won't need to create page locally and then to upload - called
         CMS (Content Management System)

    •    and a very long list to go...

First things first - I mean before you get more excited, let's prepare an environment where you can practice PHP and
can create your website.

All you have to do is to download Apache, MySQL and PHP - just install and configure - and you are good to go!!!
Sounds crazy? Don't worry :) this isn't a big deal, just a matter of few clicks. Simply download XAMPP from
http://www.apachefriends.org/download.php?xampp-win32-1.7.0-installer.exe. This is a windows based installer
which will install and configure everything for you. During installation it will ask you a few questions, just proceed
with clicks - But take care of only one thing that you need to select option for Apache and MySQL to run as a service -
when asked.

Once you have installed xampp, look for the quot;htdocsquot; folder under the installation of your xampp location. This is the
folder where you will place all of your PHP files. The better idea is to create separate folders for each project (or
website).

 Quick Note:

 Apache - Web Server
 MySQL - Database Server

Say Hello to World
The most popular and common first-code, a developer/programmer tries is quot;A Hello Worldquot; example. Fire up your
note pad and write following code in a new file.

 <?php
 echo quot;Hello Worldquot;;
 ?>

Save the file as quot;helloWorld.phpquot; under quot;htdocsquot; folder. Now fire up your favorite web browser (Firefox, IE, Opera,
Safari or etc) and type in the following address (URL) in browser's address bar.

http://localhost/helloWorld.php]http://localhost/helloWorld.php

This should load your helloWorld.php and should say:

             drperl@hotmail.com
PHP Made Easy by Dr. Perl3



Hello World

in the browser's web page display area. Waowww... we've got another developer... ;D

Now let's have a closer look into our first PHP code (usually called script).

 <?php
 ...
 ?>

The <? and ?> are the opening and closing markers (tags) of a PHP script, respectively. As I have mentioned earlier in
this article that PHP can be embedded in HTML, so the web server has to understand that which part of the web page
will be parsed (handled) by PHP itself. Usually, when we save a file as .php extension, web server automatically hands
over the calls to PHP compiler (because web server is configured for handling php files also - don't bother with it, just
carry on).

Anyway, the PHP code is enclosed between <? and ?> php tags. Alternatively you can write these tags as following
also:

 <?php
 ...
 ?>

or

 <?php
 ...
 ?>

Now, move on,

 <?php
 echo quot;Hello Worldquot;;
 ?>

quot;echoquot; is a PHP's language construct, which is also known as a function, but isn't a true function. However, echo
outputs one or more strings (data, numeric, alphabets or alphanumeric). Whatever you provide to echo, in double
quotes (quot;) or single quotes (') will be printed-out.

Add some more stuff
 <?php
 /*
 My first program in PHP.
 Written by Dr. Perl
 */


              drperl@hotmail.com
PHP Made Easy by Dr. Perl4



 // Print the message.
 echo quot;Hello Worldquot;;
 ?>

As you see /*, */ and // in above code with a few english sentences - are the quot;commentsquot; or quot;remarksquot;. A comment
is what you insert in your source code to remember or to explain something about a certain part of code, about a
chunk of code or about a single line. These are helpful for you. You can use comments to take notes, that what
exactly the code does or what has been changed since last version of this code. However, these comments are
ignored by PHP compiler and do not affect the code.

Do some variables
 <?php
 /*
 A simple calculator.
 Adds two values and prints the result.
 */

 // Define some values
 $a = 10;
 $b = 10;

 // Addition
 $c = $a + $b;

 // Print out the result
 echo $c;
 ?>

$ symbol is used to define a variable. A variable name can be anything meaningful, should start with $ sign. A variable
name itself should start with alphabet and can have numerics after that. The above code defines 3 variables, $a, $b
and $c. $a and $b contains values while $c contains the result of $a + $b (after addition). quot;echoquot; simply prints out the
$c (whatever it contains).

Alternatively, you can write above code as:

 <?php
 /*
 A simple calculator.
 Adds two values and prints the result.
 */

 // Define some values
 $a = 10;
 $b = 10;

             drperl@hotmail.com
PHP Made Easy by Dr. Perl5




 // Print out the result
 echo ($a + $b);
 ?>

Notice the 3rd variable $c is missing, because I have directly written the calculation part in the echo statement. I have
put parenthesis around the $a + $b to make it sure that it should be calculated first then should be printed out (ah!
the maths - I don't like really!!). Try it without parenthesis and figure out the results.

Summing Up
So far you have got a basic introduction to PHP, Setting up quick environment and writing basic script. Do some
practices, below is a list of few useful links which you should keep in your favorites list and may need anytime for
quick references.

Resources
www.zend.com - The PHP Company, find manual, tutorials and etc.
www.php.net - Home of PHP, find manual, and php downloads
www.mysql.com - MySQL official website
www.welive.ws - Get free space for your own website, PHP supported
www.esearchbook.com - Download free books, videos, tutorials and Share your own
www.freebookforeveryone.com - Online readable free books on PHP, PERL, Java, MySQL and etc.



Written by Dr. Perl
drperl@hotmail.com




             drperl@hotmail.com

More Related Content

What's hot

What's hot (9)

php_tizag_tutorial
php_tizag_tutorialphp_tizag_tutorial
php_tizag_tutorial
 
Basic php
Basic phpBasic php
Basic php
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
 
Php
PhpPhp
Php
 
Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
 
Software Design
Software DesignSoftware Design
Software Design
 
Php notes 01
Php notes 01Php notes 01
Php notes 01
 

Viewers also liked

Fiscal 2005 10-K Annual Report
Fiscal 2005 10-K Annual Report Fiscal 2005 10-K Annual Report
Fiscal 2005 10-K Annual Report finance2
 
2003 Merrill Lynch Global Healthcare Conference
	 2003 Merrill Lynch Global Healthcare Conference	 2003 Merrill Lynch Global Healthcare Conference
2003 Merrill Lynch Global Healthcare Conferencefinance2
 
Baird Conference Presentation
	 Baird Conference Presentation	 Baird Conference Presentation
Baird Conference Presentationfinance2
 
HIMSS Investor Briefing
HIMSS Investor BriefingHIMSS Investor Briefing
HIMSS Investor Briefingfinance2
 
Lehman Brothers 2003 Global Heathcare Conference
	 Lehman Brothers 2003 Global Heathcare Conference	 Lehman Brothers 2003 Global Heathcare Conference
Lehman Brothers 2003 Global Heathcare Conferencefinance2
 
Anatomía y Terminología basica de un BLOG
Anatomía y Terminología basica de un BLOGAnatomía y Terminología basica de un BLOG
Anatomía y Terminología basica de un BLOGPoli Suñer
 

Viewers also liked (7)

Fiscal 2005 10-K Annual Report
Fiscal 2005 10-K Annual Report Fiscal 2005 10-K Annual Report
Fiscal 2005 10-K Annual Report
 
2003 Merrill Lynch Global Healthcare Conference
	 2003 Merrill Lynch Global Healthcare Conference	 2003 Merrill Lynch Global Healthcare Conference
2003 Merrill Lynch Global Healthcare Conference
 
Paula
PaulaPaula
Paula
 
Baird Conference Presentation
	 Baird Conference Presentation	 Baird Conference Presentation
Baird Conference Presentation
 
HIMSS Investor Briefing
HIMSS Investor BriefingHIMSS Investor Briefing
HIMSS Investor Briefing
 
Lehman Brothers 2003 Global Heathcare Conference
	 Lehman Brothers 2003 Global Heathcare Conference	 Lehman Brothers 2003 Global Heathcare Conference
Lehman Brothers 2003 Global Heathcare Conference
 
Anatomía y Terminología basica de un BLOG
Anatomía y Terminología basica de un BLOGAnatomía y Terminología basica de un BLOG
Anatomía y Terminología basica de un BLOG
 

Similar to Article 01 What Is Php

Similar to Article 01 What Is Php (20)

Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php
PhpPhp
Php
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
 
PHP.docx
PHP.docxPHP.docx
PHP.docx
 
Php tizag tutorial
Php tizag tutorialPhp tizag tutorial
Php tizag tutorial
 
PHP learning
PHP learningPHP learning
PHP learning
 
php_tizag_tutorial
php_tizag_tutorialphp_tizag_tutorial
php_tizag_tutorial
 
Php tizag tutorial
Php tizag tutorial Php tizag tutorial
Php tizag tutorial
 
Php tizag tutorial
Php tizag tutorialPhp tizag tutorial
Php tizag tutorial
 
php basics
php basicsphp basics
php basics
 

Recently uploaded

Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 

Recently uploaded (20)

Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 

Article 01 What Is Php

  • 1. PHP Made Easy by Dr. Perl1 What is PHP? PHP (recursive acronym for quot;PHP: Hypertext Preprocessorquot;) is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. Simple answer, but what does that mean? An example: Example: An introductory example <html> <head> <title>Example</title> </head> <body> <?php echo quot;Hi, I'm a PHP script!quot;; ?> </body> </html> The above written quote and example is from PHP's official manual. Let me explain and introduce you with PHP in some more detail. Most of us spend a few hours on internet to check/send emails, view/post something to a discussion board (like this one), to search for some solutions using search engines, do some orkut or facebook. But a few of us will ever realize that what has made these sites so powerful, intelligent and self-maintaining? Very simple answer to this question is: Web Application Development Technologies. Don't get afraid of this heavy words term - it's all about the techniques and how you use 'em. Another simple answer would be the, PHP, ASP (Active Server Pages), JSP(Java Server Pages), CFM (Cold Fusion Markup Language) or PERL (Practical Extraction and Reporting Language). These are most renowned web scripting languages and are widely used to develop (or simply program) a website to register users, allow them to post topics, view topics, chat with friends and etc etc. In this series (PHP Made Easy by Dr. Perl) I will introduce you to the PHP, what it can do and how you can benefit from PHP? You can use PHP to: • Print current date and time on your website. • Print greetings to your visitors based on time, like Good Morning, Good Noon and etc. • Ask comments about your article. • Offer subscription to your weekly news letter. drperl@hotmail.com
  • 2. PHP Made Easy by Dr. Perl2 • Register visitors to enjoy member services. • Enable your website to accept online payments, via Credit Cards, PayPal and etc. • Keep track of daily visits on your website. • Collect statistical data from daily visits, to find out that how long a user stayed on your website and which pages were browsed mostly and likewise. • Administer your website remotely, so that you won't need to create page locally and then to upload - called CMS (Content Management System) • and a very long list to go... First things first - I mean before you get more excited, let's prepare an environment where you can practice PHP and can create your website. All you have to do is to download Apache, MySQL and PHP - just install and configure - and you are good to go!!! Sounds crazy? Don't worry :) this isn't a big deal, just a matter of few clicks. Simply download XAMPP from http://www.apachefriends.org/download.php?xampp-win32-1.7.0-installer.exe. This is a windows based installer which will install and configure everything for you. During installation it will ask you a few questions, just proceed with clicks - But take care of only one thing that you need to select option for Apache and MySQL to run as a service - when asked. Once you have installed xampp, look for the quot;htdocsquot; folder under the installation of your xampp location. This is the folder where you will place all of your PHP files. The better idea is to create separate folders for each project (or website). Quick Note: Apache - Web Server MySQL - Database Server Say Hello to World The most popular and common first-code, a developer/programmer tries is quot;A Hello Worldquot; example. Fire up your note pad and write following code in a new file. <?php echo quot;Hello Worldquot;; ?> Save the file as quot;helloWorld.phpquot; under quot;htdocsquot; folder. Now fire up your favorite web browser (Firefox, IE, Opera, Safari or etc) and type in the following address (URL) in browser's address bar. http://localhost/helloWorld.php]http://localhost/helloWorld.php This should load your helloWorld.php and should say: drperl@hotmail.com
  • 3. PHP Made Easy by Dr. Perl3 Hello World in the browser's web page display area. Waowww... we've got another developer... ;D Now let's have a closer look into our first PHP code (usually called script). <?php ... ?> The <? and ?> are the opening and closing markers (tags) of a PHP script, respectively. As I have mentioned earlier in this article that PHP can be embedded in HTML, so the web server has to understand that which part of the web page will be parsed (handled) by PHP itself. Usually, when we save a file as .php extension, web server automatically hands over the calls to PHP compiler (because web server is configured for handling php files also - don't bother with it, just carry on). Anyway, the PHP code is enclosed between <? and ?> php tags. Alternatively you can write these tags as following also: <?php ... ?> or <?php ... ?> Now, move on, <?php echo quot;Hello Worldquot;; ?> quot;echoquot; is a PHP's language construct, which is also known as a function, but isn't a true function. However, echo outputs one or more strings (data, numeric, alphabets or alphanumeric). Whatever you provide to echo, in double quotes (quot;) or single quotes (') will be printed-out. Add some more stuff <?php /* My first program in PHP. Written by Dr. Perl */ drperl@hotmail.com
  • 4. PHP Made Easy by Dr. Perl4 // Print the message. echo quot;Hello Worldquot;; ?> As you see /*, */ and // in above code with a few english sentences - are the quot;commentsquot; or quot;remarksquot;. A comment is what you insert in your source code to remember or to explain something about a certain part of code, about a chunk of code or about a single line. These are helpful for you. You can use comments to take notes, that what exactly the code does or what has been changed since last version of this code. However, these comments are ignored by PHP compiler and do not affect the code. Do some variables <?php /* A simple calculator. Adds two values and prints the result. */ // Define some values $a = 10; $b = 10; // Addition $c = $a + $b; // Print out the result echo $c; ?> $ symbol is used to define a variable. A variable name can be anything meaningful, should start with $ sign. A variable name itself should start with alphabet and can have numerics after that. The above code defines 3 variables, $a, $b and $c. $a and $b contains values while $c contains the result of $a + $b (after addition). quot;echoquot; simply prints out the $c (whatever it contains). Alternatively, you can write above code as: <?php /* A simple calculator. Adds two values and prints the result. */ // Define some values $a = 10; $b = 10; drperl@hotmail.com
  • 5. PHP Made Easy by Dr. Perl5 // Print out the result echo ($a + $b); ?> Notice the 3rd variable $c is missing, because I have directly written the calculation part in the echo statement. I have put parenthesis around the $a + $b to make it sure that it should be calculated first then should be printed out (ah! the maths - I don't like really!!). Try it without parenthesis and figure out the results. Summing Up So far you have got a basic introduction to PHP, Setting up quick environment and writing basic script. Do some practices, below is a list of few useful links which you should keep in your favorites list and may need anytime for quick references. Resources www.zend.com - The PHP Company, find manual, tutorials and etc. www.php.net - Home of PHP, find manual, and php downloads www.mysql.com - MySQL official website www.welive.ws - Get free space for your own website, PHP supported www.esearchbook.com - Download free books, videos, tutorials and Share your own www.freebookforeveryone.com - Online readable free books on PHP, PERL, Java, MySQL and etc. Written by Dr. Perl drperl@hotmail.com drperl@hotmail.com