Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
Php Tutorial

Php Tutorial

Ratings: (0)|Views: 5 |Likes:
Published by Greg Kawere
PHP tutorial will help you get up and running with PHP in no-time. The tutorial give you an overview of the basics you need to start coding in php
PHP tutorial will help you get up and running with PHP in no-time. The tutorial give you an overview of the basics you need to start coding in php

More info:

Published by: Greg Kawere on Jun 25, 2012
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





Web scriptingwith PHP, MySQL & Apache
 by Greg Chiponda published by
AfroSP (African Open Source Project)
TOC -Table of Contents
Chapter 1 : PHP BasicsChapter 2 : Variable ScopeChapter 3 : Data TypesChapter 4 : Operators & constantsChapter 5 : PHP String variablesChapter 6 : Conditional statementsChapter 7 : LoopsChapter 8 : ArraysChapter 9 : FunctionsChapter 10: Forms
Chapter 1 : PHP BasicsWhat is PHP
PHP is a open source server-side scripting language originally created by Rasmus Lerdorf in 1995 as "PersonalHome Page" but now the recursive acronym "PHP: Hypertext Preprocessor" is used to describe PHP currentfunctionality. Alternative server-side scripting languages to PHP include ASP, Java Servlets, Perl & Python.
What is PHP used for
PHP was designed to develop dynamic websites, but it can also be used for:
Server-side scripting (website development)
Command line scripting using cron (on Linux) or Task Scheduler (on Windows)
Writing desktop applications with a graphical user interface using PHP-GTK 
Types of files you can create with PHP
With PHP you can generate any type as output including :
HTML, PDF , Flash movies (using libswf and Ming)
Text, such as XHTML and any other XML file
What you need to make PHP work 
To make PHP work you need the PHP parser (CGI or server module), a web server and a web browser. ThePHP parser was re-written by Zeev Suraski and Andi Gutmans and re-named the Zend Engine. PHP can work with many database systems and servers..
How does PHP work 
PHP code is embedded in files HTML files with the file extension .php. When a you request a web page writtenin PHP, the web browser send the request to the serve which then sends the PHP file to a PHP parser whichthen delivers the web document to the web browser for you to see.
Installing PHP
You can install PHP manually or by using a pre-configured package like XAMP
Apache configuration file is called httpd.conf 
PHP configuration file is php.ini
PHP Syntax
A PHP script always starts with <?php and ends with ?> or shorthand <? and end with ?>. A PHP file musthave a .php extension. The semicolon is used in PHP to tell one set of instructions from another, so each codeline in PHP must end with a semicolon. A statement represents an instruction to the PHP engine and usualyends with a semicolon. Exceptions to this include statements that enclose other statements and statements thatend a block of code.<?phpstatement;?>
Outputing text in PHP
There are two basic statements to output text with PHP: echo and print. Language constructs.1.print ()
 print () is a language construct that behaves like a function and is used to outputs data. It acceptsa collection of characters (strings), which can be enclosed in single or double quotation marks. Itdoes not necessarily require parenthisis.2.echo ()
echo () is a language construct similar to the print () statement, it outputs data except that it doesnot return a value.
The famous “Hello World" in PHP
The 101 of learning any programming language is to know how to output “Hello World”<html><body><?php
echo "Hello World";?></body></html>
Comments in PHP
A comment is text in a script that is ignored by the PHP engine. Comments can be used to make code morereadable or to annotate a script.PHP uses two forward slashes (//) or a single hash sign (
) to make a one-linecomment and /*Comment*/ to make a multi-line comment.
PHP Variables
Variables are containers for storing information, that enable you to create templates for operations (adding twonumbers, for example) without worrying about what values the variables contain. Rules used for naming PHPvariables are:
Variables in PHP starts with a $ sign, followed by the name of the variable
The variable name must begin with a letter or the underscore character 
A variable name can only contain alpha-numeric characters & underscores (A-z, 0-9, and _ )
A variable name should not contain spaces
Variable names are case sensitive (y and Y are two different variables)
Creating PHP Variables
A variable is created the moment you first assign a value to it: i.e $firstname =”Greg” . After the execution of the statement above, the variable
will hold the value Greg.To create an empty varible you assign NULL to the variable i.e $firstname =NULL .
String variable vs Numerical variable
To create a text variable you need to put quotes around the value, whilst when creating a numerical variable youdo not need to put any quotes.<?php$txt="Hello World!";$x=16;?>
PEAR (PHP Extension and Application Repository)
PEAR provides a growing collection of libraries and scripts for extending PHP's functionality
PHP is a Loosely Typed Language
In PHP, a variable does not need to be declared before adding a value to it. PHP automatically converts thevariable to the correct data type, depending on its value.In a strongly typed programming language, you have todeclare (define) the type and name of the variable before using it.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->