Php Cheat Sheet

Explore key concepts, syntax, and usage examples for Php — perfect for quick reference.

Array
Array Functions Array Constants
  • CASE_LOWER
    💡 Used with array_change_key_case() to convert array keys to lower case
  • CASE_UPPER
    💡 Used with array_change_key_case() to convert array keys to upper case
  • SORT_ASC
    💡 Used with array_multisort() to sort in ascending order
  • SORT_DESC
    💡 Used with array_multisort() to sort in descending order
  • SORT_REGULAR
    💡 Used to compare items normally
  • SORT_NUMERIC
    💡 Used to compare items numerically
  • SORT_STRING
    💡 Used to compare items as strings
  • SORT_LOCALE_STRING
    💡 Used to compare items as strings, based on the current locale
  • COUNT_NORMAL
  • COUNT_RECURSIVE
  • EXTR_OVERWRITE
  • EXTR_SKIP
  • EXTR_PREFIX_SAME
  • EXTR_PREFIX_ALL
  • EXTR_PREFIX_INVALID
  • EXTR_PREFIX_IF_EXISTS
  • EXTR_IF_EXISTS
  • EXTR_REFS
String
String Functions String Constants
  • CRYPT_SALT_LENGTH
    💡 Contains the length of the default encryption method for the system. For standard DES encryption, the length is 2
  • CRYPT_STD_DES
    💡 Set to 1 if the standard DES-based encryption with a 2 character salt is supported, 0 otherwise
  • CRYPT_EXT_DES
    💡 Set to 1 if the extended DES-based encryption with a 9 character salt is supported, 0 otherwise
  • CRYPT_MD5
    💡 Set to 1 if the MD5 encryption with a 12 character salt starting with $1$ is supported, 0 otherwise
  • CRYPT_BLOWFISH
    💡 Set to 1 if the Blowfish encryption with a 16 character salt starting with $2$ or $2a$ is supported, 0 otherwise0
  • HTML_SPECIALCHARS
  • HTML_ENTITIES
  • ENT_COMPAT
  • ENT_QUOTES
  • ENT_NOQUOTES
  • CHAR_MAX
  • LC_CTYPE
  • LC_NUMERIC
  • LC_TIME
  • LC_COLLATE
  • LC_MONETARY
  • LC_ALL
  • LC_MESSAGES
  • STR_PAD_LEFT
  • STR_PAD_RIGHT
  • STR_PAD_BOTH
Date/Time
Date/Time Functions Date/Time Constants
  • DATE_ATOM
    💡 Atom (example: 2005-08-15T16:13:03+0000)
  • DATE_COOKIE
    💡 HTTP Cookies (example: Sun, 14 Aug 2005 16:13:03 UTC)
  • DATE_ISO8601
    💡 ISO-8601 (example: 2005-08-14T16:13:03+0000)
  • DATE_RFC822
    💡 RFC 822 (example: Sun, 14 Aug 2005 16:13:03 UTC)
  • DATE_RFC850
    💡 RFC 850 (example: Sunday, 14-Aug-05 16:13:03 UTC)
  • DATE_RFC1036
    💡 RFC 1036 (example: Sunday, 14-Aug-05 16:13:03 UTC)
  • DATE_RFC1123
    💡 RFC 1123 (example: Sun, 14 Aug 2005 16:13:03 UTC)
  • DATE_RFC2822
    💡 RFC 2822 (Sun, 14 Aug 2005 16:13:03 +0000)
  • DATE_RSS
    💡 RSS (Sun, 14 Aug 2005 16:13:03 UTC)
  • DATE_W3C
    💡 World Wide Web Consortium (example: 2005-08-14T16:13:03+0000)
Directory
Directory Functions Directory Constants
  • DIRECTORY_SEPARATOR
  • PATH_SEPARATOR
Error
Error Functions Error Constants
  • E_ERROR1
    💡 Fatal run-time errors. Errors that cannot be recovered from. Execution of the script is halted
  • E_WARNING2
    💡 Non-fatal run-time errors. Execution of the script is not halted
  • E_PARSE4
    💡 Compile-time parse errors. Parse errors should only be generated by the parser
  • E_NOTICE8
    💡 Run-time notices. The script found something that might be an error, but could also happen when running a script normally
  • E_CORE_ERROR16
    💡 Fatal errors at PHP startup. This is like an E_ERROR in the PHP core
  • E_CORE_WARNING32
    💡 Non-fatal errors at PHP startup. This is like an E_WARNING in the PHP core
  • E_COMPILE_ERROR64
    💡 Fatal compile-time errors. This is like an E_ERROR generated by the Zend Scripting Engine
  • E_COMPILE_WARNING128
    💡 Non-fatal compile-time errors. This is like an E_WARNING generated by the Zend Scripting Engine
  • E_USER_ERROR256
    💡 Fatal user-generated error. This is like an E_ERROR set by the programmer using the PHP function trigger_error()
  • E_USER_WARNING512
    💡 Non-fatal user-generated warning. This is like an E_WARNING set by the programmer using the PHP function trigger_error()
  • E_USER_NOTICE1024
    💡 User-generated notice. This is like an E_NOTICE set by the programmer using the PHP function trigger_error()
  • E_STRICT2048
    💡 Run-time notices. PHP suggest changes to your code to help interoperability and compatibility of the code
  • E_RECOVERABLE_ERROR4096
    💡 Catchable fatal error. This is like an E_ERROR but can be caught by a user defined handle (see also set_error_handler())
  • E_ALL6143
    💡 All errors and warnings, except of level E_STRICT
Math
Math Functions Math Constants
  • M_E
    💡 Returns e (approx. 2.718)
  • M_EULER
    💡 Returns Euler's constant (approx. 0.577)
  • M_LNPI
    💡 Returns the natural logarithm of PI (approx. 1.144)
  • M_LN2
    💡 Returns the natural logarithm of 2 (approx. 0.693)
  • M_LN10
    💡 Returns the natural logarithm of 10 (approx. 2.302)
  • M_LOG2E
    💡 Returns the base-2 logarithm of E (approx. 1.442)
  • M_LOG10E
    💡 Returns the base-10 logarithm of E (approx. 0.434)
  • M_PI
    💡 Returns PI (approx. 3.14159)
  • M_PI_2
    💡 Returns PI/2 (approx. 1.570)
  • M_PI_4
    💡 Returns PI/4 (approx. 0.785)
  • M_1_PI
    💡 Returns 1/PI (approx. 0.318)
  • M_2_PI
    💡 Returns 2/PI (approx. 0.636)
  • M_SQRTPI
    💡 Returns the square root of PI (approx. 1.772)
  • M_2_SQRTPI
    💡 Returns 2/square root of PI (approx. 1.128)
  • M_SQRT1_2
    💡 Returns the square root of 1/2 (approx. 0.707)
  • M_SQRT2
    💡 Returns the square root of 2 (approx. 1.414)
  • M_SQRT3
    💡 Returns the square root of 3 (approx. 1.732)
Calendar
Calendar Functions Calendar Constants
  • CAL_GREGORIAN
    💡 Gregorian calendar
  • CAL_JULIAN
    💡 Julian calendar
  • CAL_JEWISH
    💡 Jewish calendar
  • CAL_FRENCH
    💡 French Republican calendar
  • CAL_NUM_CALS
  • CAL_DOW_DAYNO
  • CAL_DOW_SHORT
  • CAL_DOW_LONG
  • CAL_MONTH_GREGORIAN_SHORT
  • CAL_MONTH_GREGORIAN_LONG
  • CAL_MONTH_JULIAN_SHORT
  • CAL_MONTH_JULIAN_LONG
  • CAL_MONTH_JEWISH
  • CAL_MONTH_FRENCH
  • CAL_EASTER_DEFAULT
  • CAL_EASTER_ROMAN
  • CAL_EASTER_ALWAYS_GREGORIAN
  • CAL_EASTER_ALWAYS_JULIAN
  • CAL_JEWISH_ADD_ALAFIM_GERESH
  • CAL_JEWISH_ADD_ALAFIM
  • CAL_JEWISH_ADD_GERESHAYIM
FTP
FTP Functions FTP Constants
  • FTP_ASCII
  • FTP_TEXT
  • FTP_BINARY
  • FTP_IMAGE
  • FTP_TIMEOUT_SEC
  • FTP_AUTOSEEK
  • FTP_AUTORESUME
    💡 Determine resume position and start position for get and put requests automatically
  • FTP_FAILED
    💡 Asynchronous transfer has failed
  • FTP_FINISHED
    💡 Asynchronous transfer has finished
  • FTP_MOREDATA
    💡 Asynchronous transfer is still active
Libxml
Libxml Functions Libxml Constants
  • LIBXML_COMPACT
    💡 Set small nodes allocation optimization. This may improve the application performance
  • LIBXML_DTDATTR
    💡 Set default DTD attributes
  • LIBXML_DTDLOAD
    💡 Load external subset
  • LIBXML_DTDVALID
    💡 Validate with the DTD
  • LIBXML_NOBLANKS
    💡 Remove blank nodes
  • LIBXML_NOCDATA
    💡 Set CDATA as text nodes
  • LIBXML_NOEMPTYTAG
    💡 Change empty tags (e.g. <br/> to <br></br>), only available in the DOMDocument->save() and DOMDocument->saveXML() functions
  • LIBXML_NOENT
    💡 Substitute entities
  • LIBXML_NOERROR
    💡 Do not show error reports
  • LIBXML_NONET
    💡 Stop network access while loading documents
  • LIBXML_NOWARNING
    💡 Do not show warning reports
  • LIBXML_NOXMLDECL
    💡 Drop the XML declaration when saving a document
  • LIBXML_NSCLEAN
    💡 Remove excess namespace declarations
  • LIBXML_XINCLUDE
    💡 Use XInclude substitution
  • LIBXML_ERR_ERROR
    💡 Get recoverable errors
  • LIBXML_ERR_FATAL
    💡 Get fatal errors
  • LIBXML_ERR_NONE
    💡 Get no errors
  • LIBXML_ERR_WARNING
    💡 Get simple warnings
  • LIBXML_VERSION
    💡 Get libxml version (e.g. 20605 or 20617)
  • LIBXML_DOTTED_VERSION
    💡 Get dotted libxml version (e.g. 2.6.5 or 2.6.17)
Mail
Mail Functions
Misc.
Misc. Functions Misc. Constants
  • CONNECTION_ABORTED
  • CONNECTION_NORMAL
  • CONNECTION_TIMEOUT
  • __COMPILER_HALT_OFFSET__
MySQLi
MySQLi Class MySQLi Stmt Class MySQLi Result Class MySQLi Driver Class MySQLi Warning Class MySQL Constants
  • MYSQLI_READ_DEFAULT_GROUP
    💡 Read options from the named group from my.cnf or the file specified with MYSQLI_READ_DEFAULT_FILE
  • MYSQLI_READ_DEFAULT_FILE
    💡 Read options from the named option file instead of from my.cnf
  • MYSQLI_OPT_CONNECT_TIMEOUT
    💡 Connect timeout in seconds
  • MYSQLI_OPT_LOCAL_INFILE
    💡 Enables command LOAD LOCAL INFILE
  • MYSQLI_INIT_COMMAND
    💡 Command to execute when connecting to MySQL server. Will automatically be re-executed when reconnecting.
  • MYSQLI_CLIENT_SSL
    💡 Use SSL (encrypted protocol). This option should not be set by application programs; it is set internally in the MySQL client library
  • MYSQLI_CLIENT_COMPRESS
    💡 Use compression protocol
  • MYSQLI_CLIENT_INTERACTIVE
    💡 Allow interactive_timeout seconds (instead of wait_timeout seconds) of inactivity before closing the connection. The client's session wait_timeout variable will be set to the value of the session interactive_timeout variable.
  • MYSQLI_CLIENT_IGNORE_SPACE
    💡 Allow spaces after function names. Makes all functions names reserved words.
  • MYSQLI_CLIENT_NO_SCHEMA
    💡 Don't allow the db_name.tbl_name.col_name syntax.
  • MYSQLI_CLIENT_MULTI_QUERIES
    💡 Allows multiple semicolon-delimited queries in a single mysqli_query() call.
  • MYSQLI_STORE_RESULT
    💡 For using buffered resultsets
  • MYSQLI_USE_RESULT
    💡 For using unbuffered resultsets
  • MYSQLI_ASSOC
    💡 Columns are returned into the array having the fieldname as the array index.
  • MYSQLI_NUM
    💡 Columns are returned into the array having an enumerated index.
  • MYSQLI_BOTH
    💡 Columns are returned into the array having both a numerical index and the fieldname as the associative index.
  • MYSQLI_NOT_NULL_FLAG
    💡 Indicates that a field is defined as NOT NULL
  • MYSQLI_PRI_KEY_FLAG
    💡 Field is part of a primary index
  • MYSQLI_UNIQUE_KEY_FLAG
    💡 Field is part of a unique index.
  • MYSQLI_MULTIPLE_KEY_FLAG
    💡 Field is part of an index.
  • MYSQLI_BLOB_FLAG
    💡 Field is defined as BLOB
  • MYSQLI_UNSIGNED_FLAG
    💡 Field is defined as UNSIGNED
  • MYSQLI_ZEROFILL_FLAG
    💡 Field is defined as ZEROFILL
  • MYSQLI_AUTO_INCREMENT_FLAG
    💡 Field is defined as AUTO_INCREMENT
  • MYSQLI_TIMESTAMP_FLAG
    💡 Field is defined as TIMESTAMP
  • MYSQLI_SET_FLAG
    💡 Field is defined as SET
  • MYSQLI_NUM_FLAG
    💡 Field is defined as NUMERIC
  • MYSQLI_PART_KEY_FLAG
    💡 Field is part of an multi-index
  • MYSQLI_GROUP_FLAG
    💡 Field is part of GROUP BY
  • MYSQLI_TYPE_DECIMAL
    💡 Field is defined as DECIMAL
  • MYSQLI_TYPE_NEWDECIMAL
    💡 Precision math DECIMAL or NUMERIC field (MySQL 5.0.3 and up)
  • MYSQLI_TYPE_BIT
    💡 Field is defined as BIT (MySQL 5.0.3 and up)
  • MYSQLI_TYPE_TINY
    💡 Field is defined as TINYINT
  • MYSQLI_TYPE_SHORT
    💡 Field is defined as SMALLINT
  • MYSQLI_TYPE_LONG
    💡 Field is defined as INT
  • MYSQLI_TYPE_FLOAT
    💡 Field is defined as FLOAT
  • MYSQLI_TYPE_DOUBLE
    💡 Field is defined as DOUBLE
  • MYSQLI_TYPE_NULL
    💡 Field is defined as DEFAULT NULL
  • MYSQLI_TYPE_TIMESTAMP
    💡 Field is defined as TIMESTAMP
  • MYSQLI_TYPE_LONGLONG
    💡 Field is defined as BIGINT
  • MYSQLI_TYPE_INT24
    💡 Field is defined as MEDIUMINT
  • MYSQLI_TYPE_DATE
    💡 Field is defined as DATE
  • MYSQLI_TYPE_TIME
    💡 Field is defined as TIME
  • MYSQLI_TYPE_DATETIME
    💡 Field is defined as DATETIME
  • MYSQLI_TYPE_YEAR
    💡 Field is defined as YEAR
  • MYSQLI_TYPE_NEWDATE
    💡 Field is defined as DATE
  • MYSQLI_TYPE_INTERVAL
    💡 Field is defined as INTERVAL
  • MYSQLI_TYPE_ENUM
    💡 Field is defined as ENUM
  • MYSQLI_TYPE_SET
    💡 Field is defined as SET
  • MYSQLI_TYPE_TINY_BLOB
    💡 Field is defined as TINYBLOB
  • MYSQLI_TYPE_MEDIUM_BLOB
    💡 Field is defined as MEDIUMBLOB
  • MYSQLI_TYPE_LONG_BLOB
    💡 Field is defined as LONGBLOB
  • MYSQLI_TYPE_BLOB
    💡 Field is defined as BLOB
  • MYSQLI_TYPE_VAR_STRING
    💡 Field is defined as VARCHAR
  • MYSQLI_TYPE_STRING
    💡 Field is defined as CHAR or BINARY
  • MYSQLI_TYPE_CHAR
    💡 Field is defined as TINYINT. For CHAR, see MYSQLI_TYPE_STRING
  • MYSQLI_TYPE_GEOMETRY
    💡 Field is defined as GEOMETRY
  • MYSQLI_NEED_DATA
    💡 More data available for bind variable
  • MYSQLI_NO_DATA
    💡 No more data available for bind variable
  • MYSQLI_DATA_TRUNCATED
    💡 Data truncation occurred. Available since PHP 5.1.0 and MySQL 5.0.5.
  • MYSQLI_ENUM_FLAG
    💡 Field is defined as ENUM. Available since PHP 5.3.0.
  • MYSQLI_CURSOR_TYPE_FOR_UPDATE
  • MYSQLI_CURSOR_TYPE_NO_CURSOR
  • MYSQLI_CURSOR_TYPE_READ_ONLY
  • MYSQLI_CURSOR_TYPE_SCROLLABLE
  • MYSQLI_STMT_ATTR_CURSOR_TYPE
  • MYSQLI_STMT_ATTR_PREFETCH_ROWS
  • MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH
  • MYSQLI_SET_CHARSET_NAME
  • MYSQLI_REPORT_INDEX
    💡 Report if no index or bad index was used in a query.
  • MYSQLI_REPORT_ERROR
    💡 Report errors from mysqli function calls.
  • MYSQLI_REPORT_STRICT
    💡 Throw a mysqli_sql_exception for errors instead of warnings.
  • MYSQLI_REPORT_ALL
    💡 Set all options on (report all).
  • MYSQLI_REPORT_OFF
    💡 Turns reporting off.
  • MYSQLI_DEBUG_TRACE_ENABLED
    💡 Is set to 1 if mysqli_debug() functionality is enabled.
  • MYSQLI_SERVER_QUERY_NO_GOOD_INDEX_USED
  • MYSQLI_SERVER_QUERY_NO_INDEX_USED
  • MYSQLI_REFRESH_GRANT
    💡 Refreshes the grant tables.
  • MYSQLI_REFRESH_LOG
    💡 Flushes the logs, like executing the FLUSH LOGS SQL statement.
  • MYSQLI_REFRESH_TABLES
    💡 Flushes the table cache, like executing the FLUSH TABLES SQL statement.
  • MYSQLI_REFRESH_HOSTS
    💡 Flushes the host cache, like executing the FLUSH HOSTS SQL statement.
  • MYSQLI_REFRESH_STATUS
    💡 Reset the status variables, like executing the FLUSH STATUS SQL statement.
  • MYSQLI_REFRESH_THREADS
    💡 Flushes the thread cache.
  • MYSQLI_REFRESH_SLAVE
    💡 On a slave replication server: resets the master server information, and restarts the slave. Like executing the RESET SLAVE SQL statement.
  • MYSQLI_REFRESH_MASTER
    💡 On a master replication server: removes the binary log files listed in the binary log index, and truncates the index file. Like executing the RESET MASTER SQL statement.
XML Parser
XML Parser Functions XML Parser Constants
  • XML_ERROR_NONE (integer)
  • XML_ERROR_NO_MEMORY (integer)
  • XML_ERROR_SYNTAX (integer)
  • XML_ERROR_NO_ELEMENTS (integer)
  • XML_ERROR_INVALID_TOKEN (integer)
  • XML_ERROR_UNCLOSED_TOKEN (integer)
  • XML_ERROR_PARTIAL_CHAR (integer)
  • XML_ERROR_TAG_MISMATCH (integer)
  • XML_ERROR_DUPLICATE_ATTRIBUTE (integer)
  • XML_ERROR_JUNK_AFTER_DOC_ELEMENT (integer)
  • XML_ERROR_PARAM_ENTITY_REF (integer)
  • XML_ERROR_UNDEFINED_ENTITY (integer)
  • XML_ERROR_RECURSIVE_ENTITY_REF (integer)
  • XML_ERROR_ASYNC_ENTITY (integer)
  • XML_ERROR_BAD_CHAR_REF (integer)
  • XML_ERROR_BINARY_ENTITY_REF (integer)
  • XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF (integer)
  • XML_ERROR_MISPLACED_XML_PI (integer)
  • XML_ERROR_UNKNOWN_ENCODING (integer)
  • XML_ERROR_INCORRECT_ENCODING (integer)
  • XML_ERROR_UNCLOSED_CDATA_SECTION (integer)
  • XML_ERROR_EXTERNAL_ENTITY_HANDLING (integer)
  • XML_OPTION_CASE_FOLDING (integer)
  • XML_OPTION_TARGET_ENCODING (integer)
  • XML_OPTION_SKIP_TAGSTART (integer)
  • XML_OPTION_SKIP_WHITE (integer)