0% found this document useful (0 votes)
81 views2 pages

PHP Cheatsheet

This document summarizes common PHP standard functions organized into categories including: - Core functions like isset(), print(), time(), and die() - Array functions like count(), print_r(), array_push(), and sort() - String functions like strlen(), strpos(), substr(), and explode() - File functions like file(), file_exists(), file_get_contents(), and scandir() - JSON functions like json_encode() and json_decode() - Session and cookie functions like setcookie(), session_start(), and session_destroy() Each function is accompanied by a brief description of its usage.

Uploaded by

Sandeep Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
81 views2 pages

PHP Cheatsheet

This document summarizes common PHP standard functions organized into categories including: - Core functions like isset(), print(), time(), and die() - Array functions like count(), print_r(), array_push(), and sort() - String functions like strlen(), strpos(), substr(), and explode() - File functions like file(), file_exists(), file_get_contents(), and scandir() - JSON functions like json_encode() and json_decode() - Session and cookie functions like setcookie(), session_start(), and session_destroy() Each function is accompanied by a brief description of its usage.

Uploaded by

Sandeep Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

PHP

PHP Standard Functions

Function Description
isset(el) Will return true 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) Prints str
time() Returns the current time in seconds
date(format, Converts an optional time in seconds to a date based on format
time)
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:
text/html") header("Content-type:
application/json")
die(message) Ends execution and sends back optional message
include(path) Includes and evalutes the specified file path

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)
Randomly selects a random entry from the array and returns the key
array_rand(arr)
(or keys) of the random entries.

CSE 154 Exam Cheat Sheet Autumn 2018 - Version 10/24/18


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 -1 if not
found
substr(s, start, len) Returns a substring of s starting at start and up to len characters in
length
trim(s) Strips whitespace (or other characters) from both ends of a string
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
join(glue, pieces) Joins pieces using glue

PHP File Functions

Function Description
file(path) Reads entire file path into an array
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(pa
Writes a string data to a file path
th, data)
scandir(path) Lists files and directories inside the specified path
glob(pattern) Lists path names matching pattern
Given a filename path, this function will strip any leading directory
basename(path)
from a file path and return just the filename

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 Session and Cookie Functions

Function Description
setcookie(name, Sends a cookie with given name and value to the user’s browser,
val, expiration) with optional expiration time given in seconds
session_start() Loads existing session data or starts a new session if one doesn’t
exist
session_destroy() Destroys old session data
session_regenerate_id(del Regenerates session id for next session, and optionally also deletes
ID) old delID

CSE 154 Exam Cheat Sheet Autumn 2018 - Version 10/24/18

You might also like