


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
Typology: Cheat Sheet
1 / 4
This page cannot be seen from the preview
Don't miss anything!
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"
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.
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
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
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
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
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
Special characters that need to be escaped to match as literals: [] โง $.|?*+(){}\