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

How To Filter Variable in PHP - filter_var() Function

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

  1. Validate filters
  2. Sanitize filters

Read more ...

How To Find First Occurrence in String - strstr() and stristr() Function

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.

Read more ...

PHP and MySQL Database Using Object-Oriented Approach

1. Create a New Connection

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

Read more ...

How To Remove Last Element of Array in PHP - array_pop() Function

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.

Read more ...

PHP Function to Get Array of Attribute Values from HTML

Document Object Model

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.

Read more ...

PHP Function to Get Array of Values from HTML

Document Object Model

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.

Read more ...

PHP Sessions

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.

Read more ...

Getting Information about Objects and Classes

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

Read more ...

Object Oriented Programming

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.

Read more ...

PHP Directory Handling

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.

Read more ...

PHP File Handling

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.

Read more ...

PHP Dates and Times

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().

Read more ...

How to Execute MySQL Query in PHP

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.

Read more ...

How to Connect Database with PHP

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.

Read more ...

PHP Language Constants

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.

Read more ...

How To Get URL of Current Page in PHP

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.

Read more ...