Sunday, March 26, 2017

PHP - Arrays

An array is a data structure that stores one or more similar type of values in a single value. For example if you want to store 100 numbers then instead of defining 100 variables its easy to define an array of 100 length.
There are three different kind of arrays and each array value is accessed using an ID c which is called array index.

PHP - Introduction

PHP started out as a small open source project that evolved as more and more people found out how useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994.
  • PHP is a recursive acronym for "PHP: Hypertext Preprocessor".
  • PHP is a server side scripting language that is embedded in HTML. It is used to manage dynamic content, databases, session tracking, even build entire e-commerce sites.

PHP - Environment Setup

Try it Option Online

We have set up the PHP Programming environment on-line, so that you can compile and execute all the available examples on line. It gives you confidence in what you are reading and enables you to verify the programs with different options. Feel free to modify any example and execute it on-line.

PHP - Syntax Overview

This chapter will give you an idea of very basic syntax of PHP and very important to make your PHP foundation strong.

Escaping to PHP

The PHP parsing engine needs a way to differentiate PHP code from other elements in the page. The mechanism for doing so is known as 'escaping to PHP'. There are four ways to do this −

PHP - Variable Types

The main way to store information in the middle of a PHP program is by using a variable.
Here are the most important things to know about variables in PHP.
  • All variables in PHP are denoted with a leading dollar sign ($).
  • The value of a variable is the value of its most recent assignment.

PHP - Constants Types

A constant is a name or an identifier for a simple value. A constant value cannot change during the execution of the script. By default, a constant is case-sensitive. By convention, constant identifiers are always uppercase. A constant name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. If you have defined a constant, it can never be changed or undefined.

PHP - Operator Types

What is Operator? Simple answer can be given using expression 4 + 5 is equal to 9. Here 4 and 5 are called operands and + is called operator. PHP language supports following type of operators.
  • Arithmetic Operators
  • Comparison Operators
  • Logical (or Relational) Operators
  • Assignment Operators
  • Conditional (or ternary) Operators

PHP - Decision Making

The if, elseif ...else and switch statements are used to take decision based on the different condition.
You can use conditional statements in your code to make your decisions. PHP supports following three decision making statements −

PHP - Loop Types

Loops in PHP are used to execute the same block of code a specified number of times. PHP supports following four loop types.
  • for − loops through a block of code a specified number of times.
  • while − loops through a block of code if and as long as a specified condition is true.
  • do...while − loops through a block of code once, and then repeats the loop as long as a special condition is true.

PHP - Strings

They are sequences of characters, like "PHP supports string operations".
NOTE − Built-in string functions is given in function reference PHP String Functions
Following are valid examples of string

PHP - Web Concepts

This session demonstrates how PHP can provide dynamic content according to browser type, randomly generated numbers or User Input. It also demonstrated how the client browser can be redirected.

Identifying Browser & Platform

PHP creates some useful environment variables that can be seen in the phpinfo.php page that was used to setup the PHP environment.

PHP - GET & POST Methods

There are two ways the browser client can send information to the web server.
  • The GET Method
  • The POST Method
Before the browser sends the information, it encodes it using a scheme called URL encoding. In this scheme, name/value pairs are joined with equal signs and different pairs are separated by the ampersand.
name1=value1&name2=value2&name3=value3

PHP - File Inclusion

You can include the content of a PHP file into another PHP file before the server executes it. There are two PHP functions which can be used to included one PHP file into another PHP file.
  • The include() Function
  • The require() Function

PHP - Files & I/O

This chapter will explain following functions related to files −
  • Opening a file
  • Reading a file
  • Writing a file
  • Closing a file

PHP - Functions

PHP functions are similar to other programming languages. A function is a piece of code which takes one more input in the form of parameter and does some processing and returns a value.
You already have seen many functions like fopen() and fread() etc. They are built-in functions but PHP gives you option to create your own functions as well.

PHP - Functions

PHP functions are similar to other programming languages. A function is a piece of code which takes one more input in the form of parameter and does some processing and returns a value.
You already have seen many functions like fopen() and fread() etc. They are built-in functions but PHP gives you option to create your own functions as well.

PHP - Cookies

Cookies are text files stored on the client computer and they are kept of use tracking purpose. PHP transparently supports HTTP cookies.
There are three steps involved in identifying returning users −

PHP - Sessions

An alternative way to make data accessible across the various pages of an entire website is to use a PHP Session.
A session creates a file in a temporary directory on the server where registered session variables and their values are stored. This data will be available to all pages on the site during that visit.
The location of the temporary file is determined by a setting in the php.ini file called session.save_path. Before using any session variable make sure you have setup this path.
When a session is started following things happen −

PHP - Sending Emails using PHP

PHP must be configured correctly in the php.ini file with the details of how your system sends email. Open php.ini file available in /etc/ directory and find the section headed [mail function].
Windows users should ensure that two directives are supplied. The first is called SMTP that defines your email server address. The second is called sendmail_from which defines your own email address.
The configuration for Windows should look something like this −

PHP - File Uploading

A PHP script can be used with a HTML form to allow users to upload files to the server. Initially files are uploaded into a temporary directory and then relocated to a target destination by a PHP script.
Information in the phpinfo.php page describes the temporary directory that is used for file uploads as upload_tmp_dir and the maximum permitted size of files that can be uploaded is stated as upload_max_filesize. These parameters are set into PHP configuration file php.ini

PHP - Coding Standard

Every company follows a different coding standard based on their best practices. Coding standard is required because there may be many developers working on different modules so if they will start inventing their own standards then source will become very un-manageable and it will become difficult to maintain that source code in future.

PHP - Predefined Variables

PHP provides a large number of predefined variables to any script which it runs. PHP provides an additional set of predefined arrays containing variables from the web server the environment, and user input. These new arrays are called superglobals −
All the following variables are automatically available in every scope.

PHP - Regular Expressions

Regular expressions are nothing more than a sequence or pattern of characters itself. They provide the foundation for pattern-matching functionality.
Using regular expression you can search a particular string inside a another string, you can replace one string by another string and you can split a string into many chunks.

PHP - Error & Exception Handling

Error handling is the process of catching errors raised by your program and then taking appropriate action. If you would handle errors properly then it may lead to many unforeseen consequences.
Its very simple in PHP to handle an errors.

PHP - Bugs Debugging

Programs rarely work correctly the first time. Many things can go wrong in your program that cause the PHP interpreter to generate an error message. You have a choice about where those error messages go. The messages can be sent along with other program output to the web browser. They can also be included in the web server error log.

PHP - Date & Time

Dates are so much part of everyday life that it becomes easy to work with them without thinking. PHP also provides powerful tools for date arithmetic that make manipulating dates easy.

Getting the Time Stamp with time()

PHP's time() function gives you all the information that you need about the current date and time. It requires no arguments but returns an integer.

PHP & MySQL

PHP will work with virtually all database software, including Oracle and Sybase but most commonly used is freely available MySQL database.

What you should already have ?

  • You have gone through MySQL tutorial to understand MySQL Basics.
  • Downloaded and installed a latest version of MySQL.

PHP & MySQL

PHP will work with virtually all database software, including Oracle and Sybase but most commonly used is freely available MySQL database.

What you should already have ?

  • You have gone through MySQL tutorial to understand MySQL Basics.
  • Downloaded and installed a latest version of MySQL.

PHP & AJAX

What is AJAX ?

  • AJAX stands for Asynchronous JavaScript and XML. AJAX is a new technique for creating better, faster, and more interactive web applications with the help of XML, HTML, CSS and Java Script.
  • Conventional web application transmit information to and from the sever using synchronous requests. This means you fill out a form, hit submit, and get directed to a new page with new information from the server.

PHP & XML

XML is a markup language that looks a lot like HTML. An XML document is plain text and contains tags delimited by < and >.There are two big differences between XML and HTML −
  • XML doesn't define a specific set of tags you must use.
  • XML is extremely picky about document structure.

Object Oriented Programming in PHP

We can imagine our universe made of different objects like sun, earth, moon etc. Similarly we can imagine our car made of different objects like wheel, steering, gear etc. Same way there is object oriented programming concepts which assume everything as an object and implement a software using different objects.

PHP For C Developers

The simplest way to think of PHP is as interpreted C that you can embed in HTML documents. The language itself is a lot like C, except with untyped variables, a whole lot of Web-specific libraries built in, and everything hooked up directly to your favorite Web server.

PHP For PERL Developers

This chapter will list out major similarities and differences in between PHP and PERL. This will help PERL developers to understand PHP very quickly and avoid common mistakes.

PHP - Form Introduction

Dynamic Websites

The Websites provide the functionalities that can use to store, update, retrieve, and delete the data in a database.

What is the Form?

A Document that containing black fields, that the user can fill the data or user can select the data.Casually the data will store in the data base

PHP - Validation Example

Required field will check whether the field is filled or not in the proper way. Most of cases we will use the * symbol for required field.

What is Validation ?

Validation means check the input submitted by the user. There are two types of validation are available in PHP. They are as follows −

PHP - Complete Form

This page explains about time real-time form with actions. Below example will take input fields as text, radio button, drop down menu, and checked box.

Example

<html>
   
   <head>
      <style>
         .error {color: #FF0000;}
      </style>

PHP - Form Introduction

Dynamic Websites

The Websites provide the functionalities that can use to store, update, retrieve, and delete the data in a database.

What is the Form?

A Document that containing black fields, that the user can fill the data or user can select the data.Casually the data will store in the data base

PHP - Validation Example

Required field will check whether the field is filled or not in the proper way. Most of cases we will use the * symbol for required field.

What is Validation ?

Validation means check the input submitted by the user. There are two types of validation are available in PHP. They are as follows −

PHP - Complete Form

This page explains about time real-time form with actions. Below example will take input fields as text, radio button, drop down menu, and checked box.

Example

<html>
   
   <head>
      <style>
         .error {color: #FF0000;}
      </style>
   </head>

PHP - Login Example

PHP login with session

Php login script is used to provide the authentication for our web pages. the Script executes after submitting the user login button.

Login Page

Login page should be as follows and works based on session. If the user close the session, it will erase the session data.

PHP - Facebook Login

We can use Facebook login to allow the users to get access into the websites. This page will explain you about login with facebook PHP SDK.

Login With Facebook

PHP - PayPal Integration

PayPal is a payment processing system, We can integrate PayPal with websites by using with php.

PayPal integration file system

PayPal integration file system included 4 files as shown below.
  • constants.php − This file has included API user name, password and signature.
  • CallerService.php − This file has included PayPal Services, which is used to call PayPal services.

PHP - MySQL Login

This tutorial demonstrates how to create a login page with MySQL Data base. Before enter into the code part, You would need special privileges to create or to delete a MySQL database. So assuming you have access to root user, you can create any database using mysql mysqladmin binary.

PHP - Ajax Search

Ajax is used to communicate with web pages and web servers. Below example demonstrate a search field using with Ajax.
<html>
   <head>
      
      <style>
         span {
            color: green;
         }
      </style>

PHP - Ajax XML Parser

Ajax XML Example

Using with Ajax we can parser xml from local directory as well as servers, Below example demonstrate how to parser xml with web browser.
<html>
   <head>
   
      <script>
         function showCD(str) {
            if (str == "") {

PHP - Ajax Auto Complete Search

Auto Complete Search

The Auto complete search box provides the suggestions when you enter data into the field. Here we are using xml to call auto complete suggestions. The below example demonstrate, How to use auto complete text box using with php.

PHP - Ajax RSS Feed Example

RSS

Really Simple Syndication is used to publish often updated information from website like audio, video, images, etc. We can integrate RSS feeds to a website by using Ajax and php. This code demonstrates how to show RSS feeds in our site.

PHP - XML Introduction

What is XML?

XML is a mark-up language to share the data across the web, XML is for both human read-able and machine read-able. Example of share-able xmls are RSS Feeds. XML parsers are useful to read and update the data by using web browsers.

PHP - Simple XML

The simple XML parser

The simple XML parser is used to parse Name, attributes and textual content.
The simple XML functions are shown below −

simplexml_load_file()

This function accepts file path as a first parameter and it is mandatory.
simplexml_load_file(($fileName,$class,$options,$ns,$is_prefix)

PHP - Simple XML GET

XML Get has used to get the node values from xml file. The following example shows, How to get the data from xml.

Note.xml

Note.xml is xml file, It can accessed by php file.
<SUBJECT>
   <COURSE>Android</COURSE>
   <COUNTRY>India</COUNTRY>
   <COMPANY>TutorialsPoint</COMPANY>
   <PRICE>$10</PRICE>
</SUBJECT>

PHP - SAX Parser Example

SAX parser has used to parse the xml file and better for memory management than sample xml parser and DOM. It does not keep any data in memory so it can be used for very large files. Following example will show how to get data from xml by using SAX API.

PHP - DOM Parser Example

A HTML Dom parser written in PHP5.X versions. Dom Parser is very good at dealing with XML as well as HTML. Dom parser travels based on tree based and before access the data, it will load the data into dom object and it will update the data to the web browser. Below Example shows how to get access to the HTML data in web browser.

PHP - Frame Works

Frame Work is collection of software or program, that trigger off easy coding and implementing the code. It helps to programmer to achieve goals in short period of time. If PHP code is integrated with frame works, you can do anything with php coding skills.

Core PHP vs Frame Works PHP

We assume that Core PHP means solving a Mathematical problem by using paper and pen. Frame work means solving Mathematical problem by using a calculator.

Core PHP-Solving Mathematical Problem

Only some students can achieve results by using paper and pen as same as in PHP. Only a few of the developers can write the code in an easy way and reliable format.

PHP - Design Patterns

Microsoft design pattern Theory is, "The document introduces patterns and then presents them in a repository, or catalogue, which is organized to help you locate the right combination of patterns that solves your problem".

PHP - Function Reference

PHP is very rich in terms of Buil-in functions. Here is the list of various important function categories. There are various other function categories which are not covered here.
Select a category to see a list of all the functions related to that category.

PHP Questions & Answers

PHP Questions and Answers has been designed with a special intention of helping students and professionals preparing for various Certification Exams and Job Interviews. This section provides a useful collection of sample Interview Questions and Multiple Choice Questions (MCQs) and their answers with appropriate explanations.

PHP - Useful Resources

The following resources contain additional information on PHP. Please use them to get more in-depth knowledge on this topic.

Useful Links on PHP

  • PHP Official Website − A complete resource for PHP stuff.
  • PEAR − PHP Extension and Application Repository, find a list of various useful PHP packages.
  • MySQL Homepage − Here you can download the latest MySQL release.

Discuss PHP

The PHP Hypertext Preprocessor (PHP) is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications. This tutorial helps you to build your base with PHP.

Perl - Introduction

Perl is a general-purpose programming language originally developed for text manipulation and now used for a wide range of tasks including system administration, web development, network programming, GUI development, and more.

Perl - Environment Setup

Try it Option Online

We have set up the Perl Programming environment online, so that you can compile and execute all the available examples online. It gives you confidence in what you are reading and enables you to verify the programs with different options. Feel free to modify any example and execute it online.

Perl - Syntax Overview

Perl borrows syntax and concepts from many languages: awk, sed, C, Bourne Shell, Smalltalk, Lisp and even English. However, there are some definite differences between the languages. This chapter is designd to quickly get you up to speed on the syntax that is expected in Perl.
A Perl program consists of a sequence of declarations and statements, which run from the top to the bottom. Loops, subroutines, and other control structures allow you to jump around within the code.

Perl - Data Types

Perl is a loosely typed language and there is no need to specify a type for your data while using in your program. The Perl interpreter will choose the type based on the context of the data itself.
Perl has three basic data types − scalars, arrays of scalars, and hashes of scalars, also known as associative arrays. Here is a little detail about these data types.

Perl - Variables

Variables are the reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.
Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals, or strings in these variables.

Perl - Scalars

A scalar is a single unit of data. That data might be an integer number, floating point, a character, a string, a paragraph, or an entire web page.
Here is a simple example of using scalar variables −
#!/usr/bin/perl

$age = 25;             # An integer assignment
$name = "John Paul";   # A string 
$salary = 1445.50;     # A floating point

Perl - Arrays

An array is a variable that stores an ordered list of scalar values. Array variables are preceded by an "at" (@) sign. To refer to a single element of an array, you will use the dollar sign ($) with the variable name followed by the index of the element in square brackets.
Here is a simple example of using the array variables −
#!/usr/bin/perl

Perl - Hashes

A hash is a set of key/value pairs. Hash variables are preceded by a percent (%) sign. To refer to a single element of a hash, you will use the hash variable name preceded by a "$" sign and followed by the "key" associated with the value in curly brackets.
Here is a simple example of using the hash variables −
#!/usr/bin/perl

Perl Conditional Statements - IF...ELSE

Perl conditional statements helps in the decision making, which require that the programmer specifies one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.

Perl - Loops

There may be a situation when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on.
Programming languages provide various control structures that allow for more complicated execution paths.
A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages −