Tuesday, 5 March 2013

PHP Index

 PHP Section One - An Introduction to PHP







> PHP Two - Getting Started With Variables




> PHP Three - Conditional Logic




> PHP Four - Working with HTML Forms




> PHP Five - Programming Loops




> PHP Six - Arrays in PHP



> PHP Seven - String Manipulation




> PHP Eight - Create your own Functions




> PHP Nine - Security Issues




> PHP Ten - Working With Files In PHP




> PHP Eleven - Date and Time Functions in PHP




> PHP Twelve - PHP and MySQL




> PHP Thirteen - Manipulate a MySQL Database




> Walkthrough One - PHP User Authentication



> Walkthrough Two - Build your own PHP Survey/Poll Application



> Walkthrough Three - How to Build an Online Forum: the database



> Walkthrough Four - The Code for the Forum


50 ESSENTIAL PHP TUTORIAL AND EXAMPLES FOR BEGINNERS


25+ PHP Tutorials & Techniques
PHP is no doubt very useful programing language now a days. It is basically made for creating dynamic web pages. It’s importance increases day by day because it is now using in content management systems like wordpress, Joomla, etc. Today i have collected 25+ php tutorials. In this list i includes tutorials from beginner to advanced level.

1- Image Resizing Made Easy with PHP

Description: PHP Tutorials & Techniques

2- Retrieve Google Analytics Visits and PageViews with PHP

Description: PHP Tutorials & Techniques

3- 9 Useful PHP Functions and Features You Need to Know

Description: PHP Tutorials & Techniques

4- How to Create a PHP/MySQL Powered Forum from Scratch

Description: PHP Tutorials & Techniques

5- How to Properly Create a Website Index Page Using PHP

Description: PHP Tutorials & Techniques

6- Creating a Bar Graph using CSS and PHP

Description: PHP Tutorials & Techniques

7- How to Validate Forms in both sides using PHP and jQuery

Description: PHP Tutorials & Techniques

8- How to Send Text Messages with PHP

Description: PHP Tutorials & Techniques

9- Rabid Ratings

Description: PHP Tutorials & Techniques

10- Caching Dynamic PHP pages easily

Description: PHP Tutorials & Techniques

11- Libchart

Description: PHP Tutorials & Techniques

12- Reading Excel Documents from PHP applications

Description: PHP Tutorials & Techniques

13- Retrieve Your Gmail Emails Using PHP and IMAP

Description: PHP Tutorials & Techniques

14- Using PHP Sessions

Description: PHP Tutorials & Techniques

15- Create a Photo Admin Site Using PHP and jQuery

Description: PHP Tutorials & Techniques

16- Vertical Bar Graphs with CSS and PHP

Description: PHP Tutorials & Techniques

17- Email Error Logs with PHP

Description: PHP Tutorials & Techniques

18- Retrieve Google Analytics Visits and PageViews with PHP

Description: PHP Tutorials & Techniques

19- Sanitize and Validate Data with PHP Filters

Description: PHP Tutorials & Techniques

20- File upload in PHP, Securing the things

Description: PHP Tutorials & Techniques

21- Build a JSON and PHP product gallery

Description: PHP Tutorials & Techniques

22- Easy PHP Pagination

Description: PHP Tutorials & Techniques

23- Logging processes with PHP

Description: PHP Tutorials & Techniques

24- PHP ajax login form using Jquery

Description: PHP Tutorials & Techniques

25- jQuery and PHP inline editing

Description: PHP Tutorials & Techniques

26- How to Code a Signup Form with Email Confirmation

Description: PHP Tutorials & Techniques

27- Create a shoutbox using PHP and AJAX (with jQuery)

Description: PHP Tutorials & Techniques

How To Upload Images And Files Php Upload Images to Webserver HTML Form PHP Function # UPLOAD FILE function upload_file(){ echo ' 
Using Php Cookies Variables Using Cookie Variables in PHP Setting cookies in php is pretty straight forward. There is a php function: setcookie(); This function mu
How To Unzip Files On Your Free Hosting Account Uzipping Files on Your Web Server If you are using a free hosting account with godaddy.com and many of the other Free hosts out there, you may have found that they don't offer you a lot o
Passing Data From One Form To Another Form Php Passing data from one form to another form To pass php data from a form and then catch that data into another form one way to accomplish this task is to intermi
Storing Image Locations Mysql Storing Image Url Location in Mysql Database Storing images in the Mysql Database using php can be done by encoding the whole image with a function called base64enco
What Is Php Explanation of PHP Basic Syntax --New to PHP Php is a language that is very much like writing c. The best feature of PHP versus c is that it is designed pri
How To Use Dreamweaver Dreamweaver - WISIWIG Dreamweaver is a tool that arguably could be called the industry standard for web design . Dreamweaver, is an Adobe product that originally b
Notepad Plus Notepad++ Download Notepad Plus Plus Notepad plus plus is an open source, free text editor. It is 
How To Open Create Write Files Php Php file functions, Opening a file in php, reading a file in php, writing a file in php In this tutorial we will look at the most commonly used file functions used in php. The
Stop Form Spam Captcha Php PHP -- How to Protect My Email Form / Contact Form Against Spam Bots Author: D.Shaun Morgan Versions and Skill Level PHP 5
Retreive Images Mysql Php Php How to get images out of mysql database with php and use them on my webpages Author: D.Shaun Morgan PHP Version - PHP 5x 
How To Make Money Online Php Making Money on the Internet Sign up for this series of free money making articles Name: 
Store Images Mysql Php Php Storing Images in Mysql Database Tutorial Outline: Creating a Test Mysql Database Example php Database Functio
Php Example Post Array Php Visual example of how PHP handles the super-global array variable "$_POST" Author: D.Shaun Morgan Versions and Skill Level 
Php Arrays Php Passing arrays to another page Author: D.Shaun Morgan Versions and Skill Level PHP Version - PHP 5x Reader skill level 
How To Write Php Functions Php How to Write PHP functions Part 1 Author: D.Shaun MorganVersions and Skill Level PHP 5 Reader skill level - Begin
How To Write Html Form PHP Php When learning PHP to build a website, one of the very first things that any newcomer, or beginner needs to learn is how to use HTML or XHTML (both will mean the same for this tutorial.) fo
Register Globals Long Arrays Php Security, php.ini, register_globals and register_long_arrays Author: D.Shaun Morgan Versions and Skill Level PHP Version - PHP 5x
How To Install Php 5 Php This is a quick start beginner's how-to manual explaining how to quickly setup a PHP 5 installation on a Windows XP PC. You must have an Apache webserver installed and working on your personal comp
Php Passing Variables Php Pass Variables from One Page to Another -- PHP Author: D.Shaun Morgan Tutorial Outline : Passing PHP variables with $_

PHP Basics

Lesson Goals

·         What is PHP
·         How PHP works.
·         To write a simple PHP page.
·         To understand and work with simple PHP variables.
·         To use PHP operators.
·         To pass values from one page to another via the URL.

Lesson Activities

1.       How PHP Works
2.       The php.ini File
3.       Basic PHP Syntax
4.       Variables
5.       PHP Operators
6.       Creating Dynamic Pages

How PHP Works

When a user navigates in her browser to a page that ends with a .php extension, the request is sent to a web server, which directs the request to the PHP interpreter.Description: http://www.learnphp-tutorial.com/images/2497/php.gif
As shown in the diagram above, the PHP interpreter processes the page, communicating with file systems, databases, and email servers as necessary, and then delivers a web page to the web server to return to the browser.
Like this PHP tutorial? Try our self-paced online PHP courses, which includes videos and exercises in addition to the content in this PHP tutorial. Not sure if you want to pay for that? Register for a free demo of the course.

The php.ini File

Before we look at PHP syntax, we should briefly mention the php.ini file. This is a plain text file that is used to configure PHP. When the PHP interpreter is started, it reads the php.ini file to determine what settings to use. We will mention this file from time to time throughout the course, but for now, it is enough that you are aware of its existence.
Like this PHP tutorial? Try our self-paced online PHP course, which includes videos and exercises in addition to the content in this PHP tutorial. Not sure if you want to pay for that? Register for a free demo of the course.

Basic PHP Syntax

PHP Tags

PHP code must be contained in special tags so that the PHP interpreter can identify it. Depending on the PHP configuration, these tags can take several forms:
<?php
  PHP CODE GOES IN HERE
?>
This is the most commonly used (and recommended) form. It is known as the XML style, because it can be used inside of an XML document without causing the document to become poorly formed.
<script language="php">
  PHP CODE GOES IN HERE
</script>
HTML or Script style tags.
<?
   PHP CODE GOES HERE
?>
"Short" tags. Must be enabled via the short_open_tag php.ini configuration file directive.
<%
   PHP CODE GOES HERE
%>
ASP-style tags. Must be enabled via the asp_tags php.ini configuration file directive.
In this manual, we will use the first form shown as it is the most common and the most portable.

PHP Statements and Whitespace

PHP statements must be inside of PHP tags to be processed by the PHP interpreter. Each PHP statement must end with a semi-colon, which tells the PHP interpreter that the statement is complete. If a semi-colon does not appear at the end of a line, the interpreter will assume that the statement continues onto the next line.
The PHP interpreter condenses all sequential whitespace in PHP scripts to a single whitespace. This convenient feature allows PHP developers to structure their code in a readable format without being concerned about the effects of line breaks and tabs.

Comments

PHP has two forms of comments:
·         Single-line comments begin with a double slash (//).
·         Multi-line comments begin with "/*" and end with "*/".

Syntax

1
2
3
4
5
6
7
// This is a single-line comment

/*
    This is
    a multi-line
    comment.
*/

PHP Functions

There are literally hundreds of built-in PHP functions that do everything from returning the current date and time on the server to pulling data out of a database. A function might take zero arguments (e.g, phpinfo(), which returns information on the PHP environment) or it might take several arguments (e.g, mail(), which takes three required and two optional arguments). The syntax for calling a function is straightforward:

Syntax

1
function_name(arguments);
The example below shows how the phpinfo() function works.

Code Sample:

PhpBasics/Demos/PhpInfo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>PHPINFO</title>
</head>
<body>
<?php
    //Output information on the PHP environment
    phpinfo();
?>
</body>
</html>

Introduction to php.net

PHP functions are well documented at http://www.php.net. You can quickly look up documentation on a function by going to http://www.php.net/function_name. For example, to see documentation on phpinfo(), go to http://www.php.net/phpinfo.
Another very good function reference is located at http://www.phpdig.net/ref.

Hello World!

It is an unwritten rule that every programming course must contain a "Hello World!" script. Here it is:

Code Sample:

PhpBasics/Demos/HelloWorld.php
1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<?php
    //Write out Hello World!
    echo 'Hello World!';
?>
</body>
</html>
Notice the following about the above code:
·         Code between <?php and ?> is processed by the PHP interpreter.
·         The echo command is used to print text back to the browser.
This code isn't very exciting. In fact, PHP doesn't buy us anything here as we could have just as easily output the result using straight HTML. There is nothing dynamic about this script. After learning about variables, we'll take a look at some more interesting examples.
Like this PHP tutorial? Try our self-paced online PHP course, which includes videos and exercises in addition to the content in this PHP tutorial. Not sure if you want to pay for that? Register for a free demo of the course.

Variables

PHP variables begin with a dollar sign ($) as shown below.

Syntax

$varName = "Value";

Variable Types

Variable Type
Explanation
Integer
whole number
Double
real number
String
string of characters
Boolean
true or false
Array
list of items
Object
instance of a class

Variable Names (Identifiers)

Variable, function and class names are all identifiers and all follow the rules above, with the exception that function names are not case sensitive.
·         consist of letters, digits, underscores and dollar signs
·         cannot begin with a digit
·         are case sensitive

Type Strength

PHP is weakly typed, meaning that variables do not need to be assigned a type (e.g, Integer) at the time they are declared. Rather, the type of a PHP variable is determined by the value the variable holds and the way in which it is used.

Hello Variables!

Here is the "Hello World!" script again, but this time we use a variable.

Code Sample:

PhpBasics/Demos/HelloVariables.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
    $greeting = 'Hello World!';
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title><?php echo $greeting; ?></title>
</head>
<body>
<?php
    echo $greeting;
?>
</body>
</html>
This time the string "Hello World!" is stored in the $greeting variable, which is output in the title and body of the page with an echo command.

Variable Scope

A variable's scope determines the locations from which the variable can be accessed. PHP variables are either superglobal, global, or local.
Variable Scope
Explanation
superglobal
Superglobal variables are predefined arrays, including $_POST and$_GET. They are accessible from anywhere on the page.
global
Global variables are visible throughout the script in which they are declared. However, they are not visible within functions in the script unless they are re-declared within the function as global variables.
function
Variables in the function scope are called local variables. Local variables are local to the function in which they are declared.

Superglobals

Again, superglobal variables are predefined arrays, including $_POST and $_GETand are accessible from anywhere on the page. The complete list of superglobals is shown below.
·         $_GET - variables passed into a page on the query string.
·         $_POST - variables passed into a page through a form using the post method.
·         $_SERVER - server environment variables (e.g, $_SERVER['HTTP_REFERER']returns the URL of the referring page).
·         $_COOKIE - cookie variables.
·         $_FILES - variables containing information about uploaded files.
·         $_ENV - PHP environment variables (e.g, $_ENV['HTTP_HOST'] returns the name of the host server.
Which environment variables are available depends on the specific server setup and configuration.
·         $_REQUEST - variables passed into a page through forms, the query string and cookies.
·         $_SESSION - session variables.
The elements within superglobal variables can be accessed in three different ways, which the authors of PHP and MySQL Web Development refer to as short style,medium style, and long style.
PHP & MySQL Web Develpoment, Third Edition.
Style
Syntax (using $_GET)
Notes
Short
$varname
·         Convenient, but it makes it difficult to distinguish superglobal variables from other variables in the code.
·         Requires register_globals config setting to be on.
Medium
$_GET['varname']
·         Recommended approach.
·         Happy medium between convenience and clarity.
·         Not available before v. 4.1.
Long
$HTTP_GET_VARS['varname']
·         Inconvenient to type.
·         Deprecated, but still supported in current versions.
·         Can be disabled via theregister_long_arrays directive in thephp.ini file.
Many of these superglobals will be covered later in the course.

Constants

Constants are like variables except that, once assigned a value, they cannot be changed. Constants are created using the define() function and by convention (but not by rule) are in all uppercase letters. Constants can be accessed from anywhere on the page.

Syntax

define('CONST_NAME',VALUE);

Variable-Testing and Manipulation Functions

For a complete list of variable functions seehttp://www.php.net/manual/en/ref.var.php.
PHP provides built-in functions for checking if a variable exists, checking if a variable holds a value, and removing a variable.
To output the results of these functions to a browser, use the var_dump() function (e.g. var_dump(isset($a));).
Function
Explanation
Example
isset()
Checks to see if a variable exists. Returns true or false.
isset($a)
unset()
Removes a variable from memory.
unset($a)
empty()
Checks to see if a variable contains a non-empty, non-false value.
empty($a)
Like this PHP tutorial? Try our self-paced online PHP course, which includes videos and exercises in addition to the content in this PHP tutorial. Not sure if you want to pay for that? Register for a free demo of the course.

PHP Operators

Operators in PHP are similar to those found in many modern C-like programming languages.
Operator
Name
Example
+
Addition
$a + $b
-
Subtraction
$a - $b
*
Multiplication
$a * $b
/
Division
$a / $b
%
Modulus
$a % $b
Mathematical Operators
Operator
Name
Example
.
Concatenation
$a . $b
'Hello' . ' world!'
String Operators

Operator
Name
Example
=
Assignment
$a = 1;
$c = 'Hello' . ' world!';
+=
-=
*=
/=
%=
.=
Combination Assignment
$a += 1;
$a -= 1;
$a *= 2;
$a /= 2;
$a %= 2;
$a .= ' world!';
++
Increment By One
$a++;
++$a;
--
Decrement By One
$a--;
--$a;
Assignment Operators
Operator
Name
Example
?:
Ternary
$foo = ($age >= 18) ? 'adult' : 'child';
@
Error Suppression
$a = @(1/0);
Other Operators
Like this PHP tutorial? Try our self-paced online PHP course, which includes videos and exercises in addition to the content in this PHP tutorial. Not sure if you want to pay for that? Register for a free demo of the course.

Creating Dynamic Pages

Single Quotes vs. Double Quotes

In PHP, for simple strings you can use single quotes and double quotes interchangeably. However, there is one important difference of which you need to be aware. Text within single quotes will not be parsed for variables and escape sequences
Escape sequences are used for characters that cannot easily be output within strings. Common escape sequences are \n for a newline, \t for a tab, \\ for a backslash, \" for a double quote, and \$ for a dollar sign.
Compare the examples below.

Code Sample:

PhpBasics/Demos/SingleQuotes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Single Quotes</title>
</head>
<body>
<?php
    $person = 'George';
    echo '\tHello\n$person!!';
?>
</body>
</html>
Because of the use of single quotes above, the string "\tHello\n$person!!" will be output literally, as shown below.Description: http://www.learnphp-tutorial.com/images/2503/SingleQuotes.gif

Code Sample:

PhpBasics/Demos/DoubleQuotes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Single Quotes</title>
</head>
<body>
<?php
    $person = "George";
    echo "\tHello\n$person!!";
?>
</body>
</html>
This time, because of the double quotes, the string will be parsed for variables and special characters and will be output as shown below.Description: http://www.learnphp-tutorial.com/images/2503/DoubleQuotes.gif
To see the effect of the special characters (\n and \t), you will have to view the source of the resulting page.

Passing Variables on the URL

A common way to pass values from the browser to the server is by appending them to the URL as follows:

Syntax

1
http://www.webucator.com/hello.php?greet=Hello&who=World
The part of the URL that follows the question mark is called the query string. One or more name-value pairs can be passed to the server in this way. Each name-value pair is separated by an ampersand (&). The processing page can read these name-value pairs and use them to determine its response.
The HTML page below shows an example of how these name-value pairs might be passed.

Code Sample:

PhpBasics/Demos/HelloHi.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Preferred Greeting</title>
</head>
<body>
    Do you prefer a formal greeting or an informal greeting?
    <ul>
        <li><a href="HelloHi.php?greet=Hello">Formal</a></li>
        <li><a href="HelloHi.php?greet=Hi">Informal</a></li>
        <li><a href="HelloHi.php?greet=Howdy">Friendly</a></li>
    </ul>
</body>
</html>

Code Sample:

PhpBasics/Demos/HelloHi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
    //Assign the passed variable to a variable with
    //a more convenient name.
    $greeting = $_GET['greet'];
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title><?= $greeting ?> World!</title>
</head>
<body>
<?php
    echo "$greeting World!";
?>
</body>
</html>
Notice the following about the code above.
·         Variable names begin with a dollar sign ($).
·         Values passed in the query string are part of the $_GET array and can be accessed using the following syntax: $_GET['fieldname'].
·         A shortcut for echo 'text to print'; is <?= 'text to print' ?>.
Many PHP developers feel that it is best practice to avoid using this shortcut syntax for echo. One reason for this is that the shortcut syntax makes the resulting PHP file impossible to parse as XML. Another is that the short_open_tag directive must be turned on for it to work. See http://us3.php.net/manual/en/ini.core.php#ini.short-open-tag
Like this PHP tutorial? Try our self-paced online PHP courses, which includes videos and exercises in addition to the content in this PHP tutorial. Not sure if you want to pay for that? Register for a free demo of the course.
Please watch this video on our YouTube channel to get a better understanding of variable scope and superglobal variables.
Like this PHP tutorial? Try our self-paced online PHP course, which includes videos and exercises in addition to the content in this PHP tutorial. Not sure if you want to pay for that? Register for a free demo of the course.
Continue to the next lesson on Flow Control »
Description: Try an online PHP class for free!

Table of Contents

1.       How PHP Works
2.       The php.ini File
3.       Basic PHP Syntax
4.       Variables
5.       PHP Operators
6.       Creating Dynamic Pages
1.       Conditional Processing
2.       Loops
1.       Indexed Arrays
2.       Associative Arrays
3.       Two-dimensional Arrays
1.       HTML Forms
1.       Formatting Strings
2.       Magic Quotes
1.       Including Files
2.       User Functions
3.       Form Processing
1.       Querying a Database
2.       Using MDB2
1.       Sessions
2.       Cookies
1.       mail()
2.       PHPMailer
1.       Opening a File
2.       Reading from a File
3.       Writing to a File
4.       File Locking
6.       Getting File Information
7.       More File Functions
8.       Directory Functions

Webucator Tutorials

·         Advanced CSS Training Tutorial
·         Ajax Training Tutorial

Webucator Courses

·         Flash CS5 Courses
·         AdWords Courses
·         Google and SEO Courses
·         Google Analytics Courses
·         Excel 2010 Courses
·         Word 2010 Courses
·         HTML5 Courses
·         Mobile Web Development Courses
·         Dreamweaver CS5 Courses
·         PowerPoint 2010 Courses
·         SharePoint 2010 Courses
·         SharePoint End User Courses
·         Office 2010 Upgrade Courses

Webucator Training

·         CSS Training
·         Flash Training
·         Marketing Training
·         Google Training
·         Social Media Training
·         Google AdWords Training
·         Google Analytics Training
·         JavaScript Training
·         Microsoft Office Training
·         Microsoft Excel Training
·         Microsoft Word Training
·         Ajax Training
·         Writing Training
·         Customer Service Training
·         HR Training
·         Business Management Training
·         HTML Training
·         Dreamweaver Training
·         Java Fundamentals Training
·         PHP Training
·         Microsoft PowerPoint Training
·         SQL Training
·         XML Training
·         jQuery Training
·         Microsoft Outlook Training
·         SharePoint Training

Self-Paced Training

·         Check out our self-paced 

No comments:

Post a Comment