PHP Tutorial

PHP stands for "PHP: Hypertext Preprocessor". It is a widely-used Open Source general-purpose scripting language especially suited for web development. It can be embedded into HTML. The main goal of the language is to allow web developers to write dynamically generated web pages quickly, but you can do much more with PHP.

What distinguishes PHP from something like client-side JavaScript is that the code is executed on the server, generating HTML which is then sent to the client. The client would receive the results of running that script, but would not know what the underlying code was.

Complete PHP Guide

The filter_var() function filters a variable with the specified filter. There are two types of filters:

  1. Validate filters
  2. Sanitize filters

The strstr() function and stristr() function can find the first occurrence of a substring (second parameter) inside another string (first parameter), and return all characters from the first occurrence till the end of the string.

1. Create a New Connection

Before you can access data in the MySQL database, you need to connect to the server.

You can use the array_pop() function to remove an element or value from the end of an array. The array_pop() function returns the last value of array. If the array is empty (or the variable is not an array), then the returned value is NULL.

The function uses Document Object Model to get array of any attribute values of particular tag element from the HTML. You can also get values from specific tags that have particular attribute and value.

The function uses Document Object Model to get array of values of any particular tag element from the HTML. You can also get values from specific tags that have particular attribute and value.

A session is a way to store information in variables. A PHP session stores data on the server rather than user's computer. In a session based environment, every user is identified through a unique number called session identifier or SID. The session IDs are randomly generated by the PHP engine which is almost impossible to guess.

PHP provides several functions that you can use to get information about objects and classes.

When applications start growing, representing more complex data structures becomes necessary. Primitive types like integers, strings, or arrays are not enough when you want to associate specific behavior to data.

Object oriented programming (OOP) is an approach to programming that uses classes and objects. In object-oriented programming, the elements of a script are objects. The objects represent the elements of the problem your script is meant to solve. For example, if the script is related to a used-car lot, the objects are probably cars and customers. Or if the script is related to outer space, the objects would probably be stars and planets.

Files are organized into directories, also called folders. This article describes how to create and remove directories and how to get a list of the files in a directory.

PHP can be used to handle files on the server. You can create, access (or read) and manipulate files dynamically using the PHP file system functions. Since PHP is a server side programming language, it allows you to work with files and directories stored on the web server. To work with a file, first you need to open the file.

Dates and times can be important elements in a web database application. PHP has the capability to recognize dates and times and handle them differently than plain character strings. Dates and times are stored by the computer in a format called a timestamp. Three important functions are date(), time() and strtotime().

After you have successfully made a new database connection in PHP, you can execute MySQL queries from the PHP code itself. Store the query in a variable as a string. Then, you can use mysqli_query() to perform queries against the database.

With PHP, you can connect to and make changes in the databases. The data in a MySQL database are stored in tables. A table is a collection of related data, and it consists of columns and rows. Databases are useful for storing information categorically.

For example, a company may have a database with the following tables - Employees, Products, Customers, Orders.

PHP provides a large number of predefined constants to any script which it runs. These constants change depending on where they are used. These special constants are case-insensitive.

There are a lot of situations where you might need to get the URL of a webpage that any user might be currently visiting. For example, you may require you to dynamically generate the title of a webpage based on its URL. There are many ways in which you can obtain the URL of a webpage.