SyntaxStudy
Sign Up
Home PHP Reference

PHP Reference

25 entries — click any item for full details and examples

String Functions

Name Description
strlen() Returns the length of a string in bytes. Use mb_strlen() for multibyte/Unicode strings.
str_replace() Replaces all occurrences of the search string with the replacement string. Case-sensitive.
strpos() Finds position of first occurrence of a substring. Returns false if not found — always use strict comparison (!==).
substr() Returns part of a string, starting at offset for the given length. Negative offset counts from the end.
strtolower() / strtoupper() Converts a string to lowercase or uppercase. Use mb_ variants for multibyte/Unicode text.
trim() Strips whitespace from both ends of a string. ltrim() strips left only; rtrim() strips right only.
explode() / implode() explode() splits a string into an array by separator; implode() (alias: join) joins an array into a string.
sprintf() Returns a formatted string. Common specifiers: %s (string), %d (integer), %f (float), %05d (zero-padded).
preg_match() / preg_replace() preg_match() performs a regex search returning match count; preg_replace() replaces regex matches.
htmlspecialchars() Converts special HTML characters to entities. Essential for preventing XSS when outputting user data.

Array Functions

Name Description
array_map() Applies a callback to each element of an array and returns a new array of results.
array_filter() Filters array elements using a callback. Without callback, removes all falsy values (0, "", null, false).
array_reduce() Iteratively reduces an array to a single value using a callback function.
array_merge() Merges arrays. String keys from later arrays overwrite; numeric keys are re-indexed.
usort() Sorts array in place using a user-defined comparison function. Use the spaceship operator <=> for concise comparisons.
in_array() / array_key_exists() in_array() checks if a value exists; array_key_exists() checks if a key exists in an array.
array_unique() Removes duplicate values from an array. Keys are preserved; use array_values() to re-index.
array_slice() Returns a portion of an array without modifying the original. Useful for pagination.

Math Functions

Name Description
round() / floor() / ceil() round() rounds to specified decimal places; floor() always rounds down; ceil() always rounds up.
rand() / random_int() Generates a random integer. Use random_int() for cryptographically secure randomness.

Date Functions

Name Description
date() Formats a Unix timestamp as a date/time string. Uses current time when no timestamp is given.
strtotime() Parses an English textual datetime description into a Unix timestamp.
DateTime class PHP 5.2 Object-oriented date/time handling with timezone support and easy arithmetic via modify() and diff().

File Functions

Name Description
file_get_contents() / file_put_contents() Read an entire file into a string or write a string to a file in a single call.
file_exists() / is_file() / is_dir() Check if a file or directory exists. is_file() confirms a regular file; is_dir() confirms a directory.