Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

PHP Cheat Sheet for CSE 154 Exam - Spring 2019, Cheat Sheet of Programming Languages

This cheat sheet provides a comprehensive overview of php functions, string functions, file functions, superglobals, pdo functions, and regex functions. It also includes a regex reference for special characters. This resource is particularly useful for the cse 154 exam in spring 2019.

What you will learn

  • What are the superglobals in PHP and how to use them?
  • What are the standard functions in PHP?
  • How to use PHP file functions to read and write files?

Typology: Cheat Sheet

2019/2020

Uploaded on 10/09/2020

alopa
alopa ๐Ÿ‡บ๐Ÿ‡ธ

4.2

(19)

256 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PHP
PHP Standard Functions
Function
Description
isset(el)
Will return false if ๎˜el ๎˜has been assigned the constant NULL, ๎˜el ๎˜has not
been set to any value yet (undefined) ๎˜el ๎˜has been deleted using the
unset function
print str
echo str
Prints ๎˜str
time()
Returns the current time in seconds
date(format, time)
Converts an optional ๎˜time ๎˜in seconds to a date based on ๎˜format
mt rand(min, max)
Returns a random integer between ๎˜min ๎˜and ๎˜max ๎˜(inclusive)
header(string)
Sends a raw HTTP header. Examples include:
header("HTTP/1.1 400 Invalid Request");
header("Content-type: text/plain");
header("Content-type: application/json");
die(message)
Ends execution and sends back optional ๎˜message
include "path"
Includes and evaluates the specified file ๎˜path๎˜ such as
"hidden/config.php"
PHP Array Functions
Function
Description
count(arr)
Returns the length of an array ๎˜arr
print_r(arr)
Prints the ๎˜arr๎˜โ€™s contents
array_pop(arr)
Pops (removes) an element off the end of the array ๎˜arr
array_shift(arr)
Shifts (removes) an element off the beginning of the array ๎˜arr
array_push(arr, el)
Pushes (adds) one or more elements onto the end of the array ๎˜arr
array_unshift(arr, el)
Prepends one or more elements to the beginning of the array ๎˜arr
sort(arr)
Sorts the array ๎˜arr
array_reverse(arr)
Returns an array with elements of ๎˜arr ๎˜in reverse order
in_array(el, arr)
Returns whether a value ๎˜el ๎˜exists in an array ๎˜arr
list(a, b, ...)
Assigns variables as if they were an array
implode(glue, pieces)
Joins array elements (๎˜pieces๎˜) with a string (๎˜glue๎˜)
array_rand(arr)
Randomly selects a random entry from the array and returns the key
(or keys) of the random entries.
PHP JSON Functions
Function
Description
json_encode(obj)
Returns JSON equivalent for the given object/array/value
json_decode(string
)
Parse the given JSON data string and returns an equivalent associative array
object
CSE 154 Exam Cheat Sheet Spring 2019 - Version 05/03/19
pf3
pf4

Partial preview of the text

Download PHP Cheat Sheet for CSE 154 Exam - Spring 2019 and more Cheat Sheet Programming Languages in PDF only on Docsity!

PHP

PHP Standard Functions

Function Description isset(el) Will return false if^ el^ has been assigned the constant NULL,^ el^ has not been set to any value yet (undefined) el has been deleted using the unset function print str echo str Prints str time() Returns the current time in seconds date(format, time) Converts an optional^ time^ in seconds to a date based on^ format mt rand(min, max) Returns a random integer between^ min^ and^ max^ (inclusive) header(string) Sends a raw HTTP header. Examples include: header("HTTP/1.1 400 Invalid Request"); header("Content-type: text/plain"); header("Content-type: application/json"); die(message) Ends execution and sends back optional^ message include "path" Includes and evaluates the specified file^ path^ such as "hidden/config.php"

PHP Array Functions

Function Description count(arr) Returns the length of an array^ arr print_r(arr) Prints the^ arrโ€™s contents array_pop(arr) Pops (removes) an element off the end of the array^ arr array_shift(arr) Shifts (removes) an element off the beginning of the array^ arr array_push(arr, el) Pushes (adds) one or more elements onto the end of the array^ arr array_unshift(arr, el) Prepends one or more elements to the beginning of the array^ arr sort(arr) Sorts the array^ arr array_reverse(arr) Returns an array with elements of^ arr^ in reverse order in_array(el, arr) Returns whether a value^ el^ exists in an array^ arr list(a, b, ...) Assigns variables as if they were an array implode(glue, pieces) Joins array elements (pieces) with a string (glue) array_rand(arr) Randomly selects a random entry from the array and returns the key (or keys) of the random entries.

PHP JSON Functions

Function Description json_encode(obj) Returns JSON equivalent for the given object/array/value json_decode(string ) Parse the given JSON data string and returns an equivalent associative array object

PHP String Functions

Function Description strlen(s) Returns the length of a string^ s strpos(str, substr) Returns the position of the first occurrence of^ substr^ in^ str, or^ FALSE^ if not found substr(s, start, len) Returns a substring of s starting at start and up to len characters in length. If s is less than start characters long, FALSE will be returned trim(s) Strips whitespace characters from both ends of a string^ s strtolower(s) Returns a lowercase version of s strtoupper(s) Returns an uppercase version of^ s explode(delimiter, s) Returns an array of substrings of s split by delimiter

PHP File Functions

Function Description file(path, [int flags = 0]) Reads entire file path into an array. Optional flags parameter can be passed in such as FILE_IGNORE_NEW_LINES or FILE_SKIP_EMPTY_LINES file_exists(path) Returns whether a file or directory^ path^ exists file_get_contents(path) Reads entire file^ path^ into a string file_put_contents(path, data) Writes a string^ data^ to a file^ path scandir(path) Returns an array of all files and directories inside the specified path including. and .. glob(pattern) Returns an array of path names matching pattern basename(path) Given a filename path, this function will strip any leading directory from a file path and return just the filename

PHP Superglobals Reference

Variable Description $_GET Superglobal array which contains query parameters passed in via a GET request $_POST (^) Superglobal array which contains POST parameters passed in via a POST request

PHP Regex Functions

Function Description preg_match(regex, str) Returns whether^ str^ matches^ regex preg_replace(regex, repl, str) Returns a new string with all substrings of str that match regex replaced by repl preg_split(regex, str) Returns an array of strings from given str split apart using given regex as delimiter

Regex Reference

Special characters that need to be escaped to match as literals: [] โˆง $.|?*+(){}\