Built-In Functions of PHP
- Built-in functions are the functions that are provided by PHP to make programming more convenient.
- Many built-in functions are present in PHP which can be employed in our code. These functions are very helpful in achieving programming goals.
- The built-in functions in PHP are very simple and easy to use. They make PHP powerful and useful.
- PHP is very rich in terms of Built-in functions. Some of the important Built-in functions of PHP are as follows:
PHP Array Functions
These functions allow interacting with and manipulating arrays in various ways. Arrays are essential for storing, managing, and operating on sets of variables.
- array() - Create an array
- array_chunk() - Splits an array into chunks of arrays
- array_diff() - Compares array values, and returns the differences
- array_fill() - Fills an array with values
- array_intersect() - Compares array values, and returns the matches
- array_merge() - Merges one or more arrays into one array
PHP Calender Functions
The calendar extension presents a series of functions to simplify converting between different calendar formats.
- cal_from_jd() - Returns information about a given calendar.
- cal_from_jd() - Converts a Julian day count into a date of a specified calendar.
- JDMonthName() - Returns a month name.
- JDDayOfWeek() - Returns the day of a week.
- jdtounix() - Converts a Julian day count to a Unix timestamp.
- unixtojd() - Converts a Unix timestamp to a Julian day count.
PHP Character Functions
The functions provided by this extension check whether a character or string falls into a certain character class according to the current locale.
- ctype_alnum() - Check for alphanumeric character(s).
- ctype_alpha() - Check for alphabetic character(s).
- ctype_digit() - Check for numeric character(s).
- ctype_space() - Check for whitespace character(s).
- ctype_upper() - Check for uppercase character(s).
- ctype_lower() - Check for lowercase character(s).
PHP Date & Time Functions
These functions allow getting the date and timing from the server where PHP scripts are running. These functions are used to format the date and time in many different ways.
- date_date_set() - Sets the date.
- date_default_timezone_get() – Returns the default time zone.
- date_default_timezone_set() - Sets the default time zone.
- date_format() - Returns date formatted according to given format.
- date_time_set() - Sets the time.
- getdate() - Returns an array that contains date and time information for a Unix timestamp.
- time() - Returns the current time as a Unix timestamp.
PHP Directory Functions
These functions are provided to manipulate any directory. PHP needs to be configured with --enable-chroot-func option to enable chroot() function.
- chdir() - Changes current directory.
- chroot() - Change the root directory.
- dir() - Opens a directory handle and returns an object.
- closedir() - Closes a directory.
- getcwd() - Gets the current working directory.
- opendir() - Open directory handle.
PHP Error Handling Functions
These are functions dealing with error handling and logging. They allow user to define their own error handling rules, as well as modify the way the errors can be logged. This allows user to change and enhance error reporting to suit their needs.
Using these logging functions, user can send messages directly to other machines, to an email, to system logs, etc. So user can selectively log and monitor the most important parts of their applications and websites.
- error_log() - Sends an error to the server error-log, to a file or to a remote destination.
- error_reporting() - Specifies which errors are reported.
- set_error_handler()- Sets a user-defined function to handle errors.
- set_exception_handler() - Sets a user-defined function to handle exceptions.
- error_get_last() - Gets the last error occurred.
- trigger_error() - Creates a user-defined error message.
PHP MySQL Function
PHP MySQLi functions gives to access the MySQLi database servers. PHP works with MySQLi version 4.1.13 or newer.
- mysqli connect - It opens a connection to a MySQLi Server.
- mysqli create db - It is used to create MySQLi connection.
- mysqli close - It is used to close MySQLi connection.
- mysqli ping - It is used to pings a server connection and reconnect to server if connection is lost.
- mysqli query - It performs a query against the database.
- mysqli real connect - This function opens a new connection to the MySQLi.
- mysqli refresh - This function refreshes tables or caches, or resets the replication server information.
- mysqli_stat - This function returns the current system status.
- mysqli rollback - This function rolls back the current transaction for the specified database connection.
PHP File System Functions
The file system functions are used to access and manipulate the file system. PHP provides all the possible functions may need to manipulate a file.
- chmod() - Changes file mode.
- file_exists() - Checks whether a file or directory exists.
- file_get_contents() - Reads entire file into a string.
- file_put_contents() - Write a string to a file.
- file() - Reads entire file into an array.
- basename() - Returns filename component of path.
PHP String Functions
PHP string functions are the part of the core. It manipulate strings in almost any possible way.
- chop() - It is used to removes whitespace.
- chunk_split() - It is used to split a string into chunks.
- crypt() - It is used to hashing the string.
- str_split() - It is used to convert a string to an array.
- strchr() - It is used to searches for the first occurrence of a string inside another.
- trim() - It used to remove the white-spaces and other characters.
PHP Network Functions
PHP Network functions give access to internet from PHP.
- fsockopen() - It is used to open internet or Unix domain socket connections.
- gethostbyname() - It is used to get the internet host name which has given by IP Address.
- gethostname() - It is used to get the host name.
- header() - It is used to send the row of HTTP Headers.
- openlog() - It used to open connection to system logger.
- setcookie() - It used to set the cookies.