PHP is the open source scripting language which allows the developer to create dynamic content which interacts with a database. It is a wide-spread fast scripting programming language. It is simple and easy to handle as compared to other scripting programming language. Due to use of an interpreter, there is no need for compilation. This cheat sheet covers all the basic and advanced topics of PHP programming language. The cheat sheet for beginners and professionals provides knowledge of the various syntax of PHP programming language. You can find freelancers who know PHP, and you also get certified freelancers for this programming language.

Variables in PHP:

The information gets stored in the middle of the PHP program using the variables. All variables in the PHP are denoted using the dollar sign ($). The variables in PHP are assigned using the = operator. The variables in PHP do not have intrinsic types. Following are the types of variables

  • Integers
  • Doubles
  • Boolean
  • Null
  • Strings
  • Array
  • Objects
  • Resources

Array:

An array is a collection of similar type of data structure which stores one or more similar type of values in the single value. Following are the types of the array in PHP.

  • Numeric array- In numeric array type, the array arrangement is with a numeric index.
  • Associative array: The array which stores the string as index is known as associative array
  • Multidimensional array: The array which is accessed using multiple indices is known as a multidimensional array.

String:

The PHP programming language supports the string operations. Following are the syntax of the string operation.

$string_1 = “This is a string in double quotes”;

$string_2 = “This is a somewhat longer, single quoted string”;

$string_39 = “This string accept up to 39 character”;

$string_0 = “”; // a string with zero characters

GET and Post Methods in PHP

GET Methods:

The method GET sends encoded information appended to the page request. The page and the encoded information are separated by a symbol(?) character.

  • The GET method can send up to 1024 characters only
  • The GET method sends the data that can be accessed using the QUERY_STRING environment variable.
  • This method cannot send the binary data such as images and word documents to the server.
  • To access all the sent information using GET method the PHP provides a $_GET associative array.

POST Methods:

Through HTTP headers the POST method transfers information.  To access all the sent information using the POST method the PHP provides a $_POST associative array.

  • The POST method does not have any restriction for data send
  • Through POST you can send ASCII and binary data.
  • The POST method sent data through HTTP header, so the security of data depends on what type of protocol you use.

PHP Regular Expression:

A regular expression is the sequence and pattern of the characters. They provide the establishment for pattern matching functionality.  A regular expression can search a particular string inside another string, and you can also replace one string with another string and split a string into many chunks.

PHP allows functions specific to two sets of regular expression function

  • POSIX Regular Expressions
  • PERL Style Regular Expressions

Predefined Variables in PHP

PHP provides various types of predefined variables to any script which it runs. Following are the list of predefined variables.

$GLOBAL

$_SERVER

$_GET

$_POST

$_FILES

$_COOKIE

$_SESSION

$_FILE

$_REQUEST

PHP Error Handling:

It is the process of catching the errors generated by your program and then taking appropriate action. PHP provides the Using die() function that will help to check all possible error condition before going ahead and take proper action when required. You can find freelancers who know PHP, and you also get certified freelancers for this programming language.

<?php

if(!file_exists(“/tmp/CheatSheet.txt”)) {

die(“File not found”);

}else {

$file = fopen(“/tmp/CheatSheet.txt”,”r”);

print “Open file successfully”;

}

// Test of the code here.

?>

You can also handle the error using your function. Following are the syntax of the error handling function.

error_function(error_level,error_message, error_file,error_line,error_context);

Some of the inbuilt functions of Error Handling in PHP

  • error_level: It specifies the error report level for the user-defined error.
  • error_message: for user-defined error, it specifies the error message.
  • error_file: It specifies the file name in which error occurred.
  • error_line: This function specifies the line number for which error occurs.
  • error_contex: Specifies an array containing every variable and their values in use when the error occurred.

Summary:

This article is about the PHP programming cheat sheet. This cheat sheet covers all the basic and advanced topics of PHP programming language. The cheat sheet is the best for beginners and professionals which provide knowledge of the various syntax of PHP programming language.

Kitty Gupta