PHP
What is PHP?
- PHP is an acronym for "PHP: Hypertext Preprocessor"
- PHP is a widely-used, open source scripting language
- PHP scripts are executed on the server
- PHP is free to download and use.
What Can PHP Do?
- PHP can generate dynamic page content
- PHP can create, open, read, write, delete, and close files on the server
- PHP can collect form data
- PHP can send and receive cookies
- PHP can add, delete, modify data in your database
- PHP can be used to control user-access
- PHP can encrypt data
PHP Data Types
Variables can store data of different types, and different data types can do different things.
PHP supports the following data types:
- String = (A string is a sequence of characters, like "Hello world!".)
- Integer = ( An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647.)
- Float = (floating point numbers - also called double) = (A float (floating point number) is a number with a decimal point or a number in exponential form.)
- Boolean = (A Boolean represents two possible states: TRUE or FALSE.)
- Array = (An array stores multiple values in one single variable.)
- Object = (An object is a data type which stores data and information on how to process that data.)
- NULL = (Null is a special data type which can have only one value: NULL.
A variable of data type NULL is a variable that has no value assigned to it.) - Resource = (The special resource type is not an actual data type. It is the storing of a reference to functions and resources external to PHP.)
PHP Operators
Operators are used to perform operations on variables and values.
PHP divides the operators in the following groups:
- Arithmetic operators = (The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.)
- Assignment operators = (The PHP assignment operators are used with numeric values to write a value to a variable.)
- Comparison operators = (The PHP comparison operators are used to compare two values (number or string):)
- Increment/Decrement operators = (The PHP increment operators are used to increment a variable's value.
The PHP decrement operators are used to decrement a variable's value.) - Logical operators = (The PHP logical operators are used to combine conditional statements.)
- String operators = (PHP has two operators that are specially designed for strings.)
- Array operators = (The PHP array operators are used to compare arrays.)
- Conditional assignment operators = (The PHP conditional assignment operators are used to set a value depending on conditions:)
PHP Loops
Loops are used to execute the same block of code again and again, as long as a certain condition is true.
In PHP, we have the following loop types:
while
-( loops through a block of code as long as the specified condition is true)do...while
- loops through a block of code once, and then repeats the loop as long as the specified condition is truefor
- loops through a block of code a specified number of timesforeach
- loops through a block of code for each element in an array
PHP Global Variables - Superglobals
Some predefined variables in PHP are "superglobals", which means that they are always accessible, regardless of scope - and you can access them from any function, class or file without having to do anything special.
The PHP superglobal variables are:
- $GLOBALS = ($GLOBALS is a PHP super global variable which is used to access global variables from anywhere in the PHP script (also from within functions or methods).)
- $_SERVER = ($_SERVER is a PHP super global variable which holds information about headers, paths, and script locations.)
- $_REQUEST = (PHP $_REQUEST is a PHP super global variable which is used to collect data after submitting an HTML form.)
- $_POST = (PHP $_POST is a PHP super global variable which is used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables.)
- $_GET = (PHP $_GET is a PHP super global variable which is used to collect form data after submitting an HTML form with method="get".
$_GET can also collect data sent in the URL.) - $_FILES
- $_ENV
- $_COOKIE
- $_SESSION
What is a Cookie?
=> A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.(A cookie is created with the
setcookie()
function.)What is a PHP Session?
=> A session is a way to store information (in variables) to be used across multiple pages. So; Session variables hold information about one single user, and are available to all pages in one application.
(A session is started with the
session_start()
function.)What is JSON?
JSON stands for JavaScript Object Notation, and is a syntax for storing and exchanging data.
Since the JSON format is a text-based format, it can easily be sent to and from a server, and used as a data format by any programming language.
PHP and JSON
PHP has some built-in functions to handle JSON.
First, we will look at the following two functions:
- json_encode()
- json_decode()..........
Comments
Post a Comment