Search:

Categories



PHP Date Functions

Function Reference
checkdate()  Validates a Gregorian date
date_add()  Adds days, months, years, hours, minutes, and seconds to a date
date_create_from_format()  Returns a new DateTime object formatted according to a specified format
date_create()  Returns a new DateTime object
date_date_set()  Sets a new date
date_default_timezone_get()  Returns the default timezone used by all date/time functions
date_default_timezone_set()  Sets the default timezone used by all date/time functions
date_diff()  Returns the difference between two dates
date_format()  Returns a date formatted according to a specified format
date_get_last_errors()  Returns the warnings/errors found in a date string
date_interval_create_from_date_string()  Sets up a DateInterval from the relative parts of the string
date_interval_format()  Formats the interval
date_isodate_set()  Sets the ISO date
date_modify()  Modifies the timestamp
date_offset_get()  Returns the timezone offset
date_parse_from_format()  Returns an associative array with detailed info about a specified date, according to a specified format
date_parse()  Returns an associative array with detailed info about a specified date
date_sub()  Subtracts days, months, years, hours, minutes, and seconds from a date
date_sun_info()  Returns an array containing info about sunset/sunrise and twilight begin/end, for a specified day and location
date_sunrise()  Returns the sunrise time for a specified day and location
date_sunset()  Returns the sunset time for a specified day and location
date_time_set()  Sets the time
date_timestamp_get()  Returns the Unix timestamp
date_timestamp_set()  Sets the date and time based on a Unix timestamp
date_timezone_get()  Returns the time zone of the given DateTime object
date_timezone_set()  Sets the time zone for the DateTime object
date()  Formats a local date and time
getdate()  Returns date/time information of a timestamp or the current local date/time
gettimeofday()  Returns the current time
gmdate()  Formats a GMT/UTC date and time
gmmktime()  Returns the Unix timestamp for a GMT date
gmstrftime()  Formats a GMT/UTC date and time according to locale settings
idate()  Formats a local time/date as integer
localtime()  Returns the local time
microtime()  Returns the current Unix timestamp with microseconds
mktime()  Returns the Unix timestamp for a date
strftime()  Formats a local time and/or date according to locale settings
strptime()  Parses a time/date generated with strftime()
strtotime()  Parses an English textual datetime into a Unix timestamp
time()  Returns the current time as a Unix timestamp
timezone_abbreviations_list()  Returns an associative array containing dst, offset, and the timezone name
timezone_identifiers_list()  Returns an indexed array with all timezone identifiers
timezone_location_get()  Returns location information for a specified timezone
timezone_name_from_ abbr()  Returns the timezone name from abbreviation
timezone_name_get()  Returns the name of the timezone
timezone_offset_get()  Returns the timezone offset from GMT
timezone_open()  Creates new DateTimeZone object
timezone_transitions_get()  Returns all transitions for the timezone
timezone_version_get()  Returns the version of the timezone db
FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditDeliciousShare

PHP MySQLI functions

Function Reference
mysqli_affected_rows() Returns the number of affected rows in the previous MySQL operation
mysqli_autocommit() Turns on or off auto-committing database modifications
mysqli_change_user() Changes the user of the specified database connection
mysqli_character_set_name() Returns the default character set for the database connection
mysqli_close() Closes a previously opened database connection
mysqli_commit() Commits the current transaction
mysqli_connect_errno() Returns the error code from the last connection error
mysqli_connect_error() Returns the error description from the last connection error
mysqli_connect() Opens a new connection to the MySQL server
mysqli_data_seek() Adjusts the result pointer to an arbitrary row in the result-set
mysqli_debug() Performs debugging operations
mysqli_dump_debug_info() Dumps debugging info into the log
mysqli_errno() Returns the last error code for the most recent function call
mysqli_error_list() Returns a list of errors for the most recent function call
mysqli_error() Returns the last error description for the most recent function call
mysqli_fetch_all() Fetches all result rows as an associative array, a numeric array, or both
mysqli_fetch_array() Fetches a result row as an associative, a numeric array, or both
mysqli_fetch_assoc() Fetches a result row as an associative array
mysqli_fetch_field_direct() Returns meta-data for a single field in the result set, as an object
mysqli_fetch_field() Returns the next field in the result set, as an object
mysqli_fetch_fields() Returns an array of objects that represent the fields in a result set
mysqli_fetch_lengths() Returns the lengths of the columns of the current row in the result set
mysqli_fetch_object() Returns the current row of a result set, as an object
mysqli_fetch_row() Fetches one row from a result-set and returns it as an enumerated array
mysqli_field_count() Returns the number of columns for the most recent query
mysqli_field_seek() Sets the field cursor to the given field offset
mysqli_field_tell() Returns the position of the field cursor
mysqli_free_result() Frees the memory associated with a result
mysqli_get_charset() Returns a character set object
mysqli_get_client_info() Returns the MySQL client library version
mysqli_get_client_stats() Returns statistics about client per-process
mysqli_get_client_version() Returns the MySQL client library version as an integer
mysqli_get_connection_stats() Returns statistics about the client connection
mysqli_get_host_info() Returns the MySQL server hostname and the connection type
mysqli_get_proto_info() Returns the MySQL protocol version
mysqli_get_server_info() Returns the MySQL server version
mysqli_get_server_version() Returns the MySQL server version as an integer
mysqli_info() Returns information about the most recently executed query
mysqli_init() Initializes MySQLi and returns a resource for use with mysqli_real_connect()
mysqli_insert_id() Returns the auto-generated id used in the last query
mysqli_kill() Asks the server to kill a MySQL thread
mysqli_more_results() Checks if there are more results from a multi query
mysqli_multi_query() Performs one or more queries on the database
mysqli_next_result() Prepares the next result set from mysqli_multi_query()
mysqli_num_fields() Returns the number of fields in a result set
mysqli_num_rows() Returns the number of rows in a result set
mysqli_options() Sets extra connect options and affect behavior for a connection
mysqli_ping() Pings a server connection, or tries to reconnect if the connection has gone down
mysqli_prepare() Prepares an SQL statement for execution
mysqli_query() Performs a query against the database
mysqli_real_connect() Opens a new connection to the MySQL server
mysqli_real_escape_string() Escapes special characters in a string for use in an SQL statement
mysqli_real_query() Executes an SQL query
mysqli_reap_async_query() Returns the result from async query
mysqli_refresh() Refreshes tables or caches, or resets the replication server information
mysqli_rollback() Rolls back the current transaction for the database
mysqli_select_db() Changes the default database for the connection
mysqli_set_charset() Sets the default client character set
mysqli_set_local_infile_default() Unsets user defined handler for load local infile command
mysqli_set_local_infile_handler() Set callback function for LOAD DATA LOCAL INFILE command
mysqli_sqlstate() Returns the SQLSTATE error code for the last MySQL operation
mysqli_ssl_set() Used to establish secure connections using SSL
mysqli_stat() Returns the current system status
mysqli_stmt_init() Initializes a statement and returns an object for use with mysqli_stmt_prepare()
mysqli_store_result() Transfers a result set from the last query
mysqli_thread_id() Returns the thread ID for the current connection
mysqli_thread_safe() Returns whether the client library is compiled as thread-safe
mysqli_use_result() Initiates the retrieval of a result set from the last query executed using the mysqli_real_query()
mysqli_warning_count() Returns the number of warnings from the last query in the connection
FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditDeliciousShare

PHP String functions

Function Description
addcslashes()  Returns a string with backslashes in front of the specified characters
addslashes()  Returns a string with backslashes in front of predefined characters
bin2hex()  Converts a string of ASCII characters to hexadecimal values
chop()  Removes whitespace or other characters from the right end of a string
chr()  Returns a character from a specified ASCII value
chunk_split()  Splits a string into a series of smaller parts
convert_cyr_string()  Converts a string from one Cyrillic character-set to another
convert_uudecode()  Decodes a uuencoded string
convert_uuencode()  Encodes a string using the uuencode algorithm
count_chars()  Returns information about characters used in a string
crc32()  Calculates a 32-bit CRC for a string
crypt()  One-way string encryption (hashing)
echo()  Outputs one or more strings
explode()  Breaks a string into an array
fprintf()  Writes a formatted string to a specified output stream
get_html_translation_table()  Returns the translation table used by htmlspecialchars() and htmlentities()
hebrev()  Converts Hebrew text to visual text
hebrevc()  Converts Hebrew text to visual text and new lines (\n) into <br>
hex2bin()  Converts a string of hexadecimal values to ASCII characters
html_entity_decode()  Converts HTML entities to characters
htmlentities()  Converts characters to HTML entities
htmlspecialchars_decode()  Converts some predefined HTML entities to characters
htmlspecialchars()  Converts some predefined characters to HTML entities
implode()  Returns a string from the elements of an array
join()  Alias of implode()
lcfirst()  Converts the first character of a string to lowercase
levenshtein()  Returns the Levenshtein distance between two strings
localeconv()  Returns locale numeric and monetary formatting information
ltrim()  Removes whitespace or other characters from the left side of a string
md5()  Calculates the MD5 hash of a string
md5_file()  Calculates the MD5 hash of a file
metaphone()  Calculates the metaphone key of a string
money_format()  Returns a string formatted as a currency string
nl_langinfo()  Returns specific local information
nl2br()  Inserts HTML line breaks in front of each newline in a string
number_format()  Formats a number with grouped thousands
ord()  Returns the ASCII value of the first character of a string
parse_str()  Parses a query string into variables
print()  Outputs one or more strings
printf()  Outputs a formatted string
quoted_printable_decode()  Converts a quoted-printable string to an 8-bit string
quoted_printable_encode()  Converts an 8-bit string to a quoted printable string
quotemeta()  Quotes meta characters
rtrim()  Removes whitespace or other characters from the right side of a string
setlocale()  Sets locale information
sha1()  Calculates the SHA-1 hash of a string
sha1_file()  Calculates the SHA-1 hash of a file
similar_text()  Calculates the similarity between two strings
soundex()  Calculates the soundex key of a string
sprintf()  Writes a formatted string to a variable
sscanf()  Parses input from a string according to a format
str_getcsv()  Parses a CSV string into an array
str_ireplace()  Replaces some characters in a string (case-insensitive)
str_pad()  Pads a string to a new length
str_repeat()  Repeats a string a specified number of times
str_replace()  Replaces some characters in a string (case-sensitive)
str_rot13()  Performs the ROT13 encoding on a string
str_shuffle()  Randomly shuffles all characters in a string
str_split()  Splits a string into an array
str_word_count()  Count the number of words in a string
strcasecmp()  Compares two strings (case-insensitive)
strchr()  Finds the first occurrence of a string inside another string (alias of strstr())
strcmp()  Compares two strings (case-sensitive)
strcoll()  Compares two strings (locale based string comparison)
strcspn()  Returns the number of characters found in a string before any part of some specified characters are found
strip_tags()  Strips HTML and PHP tags from a string
stripcslashes()  Unquotes a string quoted with addcslashes()
stripslashes()  Unquotes a string quoted with addslashes()
stripos()  Returns the position of the first occurrence of a string inside another string (case-insensitive)
stristr()  Finds the first occurrence of a string inside another string (case-insensitive)
strlen()  Returns the length of a string
strnatcasecmp()  Compares two strings using a “natural order” algorithm (case-insensitive)
strnatcmp()  Compares two strings using a “natural order” algorithm (case-sensitive)
strncasecmp()  String comparison of the first n characters (case-insensitive)
strncmp()  String comparison of the first n characters (case-sensitive)
strpbrk()  Searches a string for any of a set of characters
strpos()  Returns the position of the first occurrence of a string inside another string (case-sensitive)
strrchr()  Finds the last occurrence of a string inside another string
strrev()  Reverses a string
strripos()  Finds the position of the last occurrence of a string inside another string (case-insensitive)
strrpos()  Finds the position of the last occurrence of a string inside another string (case-sensitive)
strspn()  Returns the number of characters found in a string that contains only characters from a specified charlist
strstr()  Finds the first occurrence of a string inside another string (case-sensitive)
strtok()  Splits a string into smaller strings
strtolower()  Converts a string to lowercase letters
strtoupper()  Converts a string to uppercase letters
strtr()  Translates certain characters in a string
substr()  Returns a part of a string
substr_compare()  Compares two strings from a specified start position (binary safe and optionally case-sensitive)
substr_count()  Counts the number of times a substring occurs in a string
substr_replace()  Replaces a part of a string with another string
trim()  Removes whitespace or other characters from both sides of a string
ucfirst()  Converts the first character of a string to uppercase
ucwords()  Converts the first character of each word in a string to uppercase
vfprintf()  Writes a formatted string to a specified output stream
vprintf()  Outputs a formatted string
vsprintf()  Writes a formatted string to a variable
wordwrap()  Wraps a string to a given number of characters
FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditDeliciousShare

PHP Math functions

PHP Function Description
abs() Returns the absolute (positive) value of a number
acos() Returns the arc cosine of a number
acosh() Returns the inverse hyperbolic cosine of a number
asin() Returns the arc sine of a number
asinh() Returns the inverse hyperbolic sine of a number
atan() Returns the arc tangent of a number in radians
atan2() Returns the arc tangent of two variables x and y
atanh() Returns the inverse hyperbolic tangent of a number
base_convert() Converts a number from one number base to another
bindec() Converts a binary number to a decimal number
ceil() Rounds a number up to the nearest integer
cos() Returns the cosine of a number
cosh() Returns the hyperbolic cosine of a number
decbin() Converts a decimal number to a binary number
dechex() Converts a decimal number to a hexadecimal number
decoct() Converts a decimal number to an octal number
deg2rad() Converts a degree value to a radian value
exp() Calculates the exponent of e
expm1() Returns exp(x) – 1
floor() Rounds a number down to the nearest integer
fmod() Returns the remainder of x/y
getrandmax() Returns the largest possible value returned by rand()
hexdec() Converts a hexadecimal number to a decimal number
hypot() Calculates the hypotenuse of a right-angle triangle
is_finite() Checks whether a value is finite or not
is_infinite() Checks whether a value is infinite or not
is_nan() Checks whether a value is ‘not-a-number’
lcg_value() Returns a pseudo random number in a range between 0 and 1
log() Returns the natural logarithm of a number
log10() Returns the base-10 logarithm of a number
log1p() Returns log(1+number)
max() Returns the highest value in an array, or the highest value of several specified values
min() Returns the lowest value in an array, or the lowest value of several specified values
mt_getrandmax() Returns the largest possible value returned by mt_rand()
mt_rand() Generates a random integer using Mersenne Twister algorithm
mt_srand() Seeds the Mersenne Twister random number generator
octdec() Converts an octal number to a decimal number
pi() Returns the value of PI
pow() Returns x raised to the power of y
rad2deg() Converts a radian value to a degree value
rand() Generates a random integer
round() Rounds a floating-point number
sin() Returns the sine of a number
sinh() Returns the hyperbolic sine of a number
sqrt() Returns the square root of a number
srand() Seeds the random number generator
tan() Returns the tangent of a number
tanh() Returns the hyperbolic tangent of a number
INF INF The infinite PHP 4
M_E 2.7182818284590452354 Returns e PHP 4
M_EULER 0.57721566490153286061 Returns Euler constant PHP 4
M_LNPI 1.14472988584940017414 Returns the natural logarithm of PI: log_e(pi) PHP 5.2
M_LN2 0.69314718055994530942 Returns the natural logarithm of 2: log_e 2 PHP 4
M_LN10 2.30258509299404568402 Returns the natural logarithm of 10: log_e 10 PHP 4
M_LOG2E 1.4426950408889634074 Returns the base-2 logarithm of E: log_2 e PHP 4
M_LOG10E 0.43429448190325182765 Returns the base-10 logarithm of E: log_10 e PHP 4
M_PI 3.14159265358979323846 Returns Pi PHP 4
M_PI_2 1.57079632679489661923 Returns Pi/2 PHP 4
M_PI_4 0.78539816339744830962 Returns Pi/4 PHP 4
M_1_PI 0.31830988618379067154 Returns 1/Pi PHP 4
M_2_PI 0.63661977236758134308 Returns 2/Pi PHP 4
M_SQRTPI 1.77245385090551602729 Returns the square root of PI: sqrt(pi) PHP 5.2
M_2_SQRTPI 1.12837916709551257390 Returns 2/square root of PI: 2/sqrt(pi) PHP 4
M_SQRT1_2 0.70710678118654752440 Returns the square root of 1/2: 1/sqrt(2) PHP 4
M_SQRT2 1.41421356237309504880 Returns the square root of 2: sqrt(2) PHP 4
M_SQRT3 1.73205080756887729352 Returns the square root of 3: sqrt(3) PHP 5.2
NAN NAN Not A Number PHP 4
PHP_ROUND_HALF_UP 1 Round halves up PHP 5.3
PHP_ROUND_HALF_DOWN 2 Round halves down PHP 5.3
PHP_ROUND_HALF_EVEN 3 Round halves to even numbers PHP 5.3
PHP_ROUND_HALF_ODD 4 Round halves to odd numbers PHP 5.3
FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditDeliciousShare

CSV to array

function csv_to_array($filename, $delimiter) {
    ini_set('auto_detect_line_endings', true);

    if(!file_exists($filename) || !is_readable($filename)) {
        return FALSE;
    }

    $header = NULL;
    $data = array();
    if (($handle = fopen($filename, 'r')) !== FALSE)   {
        while (($row = fgetcsv($handle, $delimiter)) !== FALSE)
        {
            if(!$header) {
                $header = $row;
            } else {
                $data[] = array_combine($header, $row);
            }
        }
        fclose($handle);
    }
    return $data;
}
FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditDeliciousShare

List all active plugins

Lists all active plugins in wordpress, may be handy if you run a few sites

function wp_list_active_site_plugins() {
    $the_plugs = get_option('active_plugins'); 
    foreach($the_plugs as $key => $value) {
        $string = explode('/',$value); // Folder name will be displayed
        echo $string[0] ."\n";
    }
}

wp_list_active_site_plugins();
FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditDeliciousShare