PHP Functions

Ace your homework & exams now with Quizwiz!

curl_setopt() options

Option Set value to Notes CURLOPT_AUTOREFERER TRUE to automatically set the Referer: field in requests where it follows a Location: redirect. CURLOPT_BINARYTRANSFER TRUE to return the raw output when CURLOPT_RETURNTRANSFER is used. From PHP 5.1.3, this option has no effect: the raw output will always be returned when CURLOPT_RETURNTRANSFER is used. CURLOPT_COOKIESESSION TRUE to mark this as a new cookie "session". It will force libcurl to ignore all cookies it is about to load that are "session cookies" from the previous session. By default, libcurl always stores and loads all cookies, independent if they are session cookies or not. Session cookies are cookies without expiry date and they are meant to be alive and existing for this "session" only. CURLOPT_CERTINFO TRUE to output SSL certification information to STDERR on secure transfers. Added in cURL 7.19.1. Available since PHP 5.3.2. Requires CURLOPT_VERBOSE to be on to have an effect. CURLOPT_CONNECT_ONLY TRUE tells the library to perform all the required proxy authentication and connection setup, but no data transfer. This option is implemented for HTTP, SMTP and POP3. Added in 7.15.2. Available since PHP 5.5.0. CURLOPT_CRLF TRUE to convert Unix newlines to CRLF newlines on transfers. CURLOPT_DNS_USE_GLOBAL_CACHE TRUE to use a global DNS cache. This option is not thread-safe and is enabled by default. CURLOPT_FAILONERROR TRUE to fail verbosely if the HTTP code returned is greater than or equal to 400. The default behavior is to return the page normally, ignoring the code. CURLOPT_SSL_FALSESTART TRUE to enable TLS false start. Added in cURL 7.42.0. Available since PHP 7.0.7. CURLOPT_FILETIME TRUE to attempt to retrieve the modification date of the remote document. This value can be retrieved using the CURLINFO_FILETIME option with curl_getinfo(). CURLOPT_FOLLOWLOCATION TRUE to follow any "Location: " header that the server sends as part of the HTTP header (note this is recursive, PHP will follow as many "Location: " headers that it is sent, unless CURLOPT_MAXREDIRS is set). CURLOPT_FORBID_REUSE TRUE to force the connection to explicitly close when it has finished processing, and not be pooled for reuse. CURLOPT_FRESH_CONNECT TRUE to force the use of a new connection instead of a cached one. CURLOPT_FTP_USE_EPRT TRUE to use EPRT (and LPRT) when doing active FTP downloads. Use FALSE to disable EPRT and LPRT and use PORT only. CURLOPT_FTP_USE_EPSV TRUE to first try an EPSV command for FTP transfers before reverting back to PASV. Set to FALSE to disable EPSV. CURLOPT_FTP_CREATE_MISSING_DIRS TRUE to create missing directories when an FTP operation encounters a path that currently doesn't exist. CURLOPT_FTPAPPEND TRUE to append to the remote file instead of overwriting it. CURLOPT_TCP_NODELAY TRUE to disable TCP's Nagle algorithm, which tries to minimize the number of small packets on the network. Available since PHP 5.2.1 for versions compiled with libcurl 7.11.2 or greater. CURLOPT_FTPASCII An alias of CURLOPT_TRANSFERTEXT. Use that instead. CURLOPT_FTPLISTONLY TRUE to only list the names of an FTP directory. CURLOPT_HEADER TRUE to include the header in the output. CURLINFO_HEADER_OUT TRUE to track the handle's request string. Available since PHP 5.1.3. The CURLINFO_ prefix is intentional. CURLOPT_HTTPGET TRUE to reset the HTTP request method to GET. Since GET is the default, this is only necessary if the request method has been changed. CURLOPT_HTTPPROXYTUNNEL TRUE to tunnel through a given HTTP proxy. CURLOPT_MUTE TRUE to be completely silent with regards to the cURL functions. Removed in cURL 7.15.5 (You can use CURLOPT_RETURNTRANSFER instead) CURLOPT_NETRC TRUE to scan the ~/.netrc file to find a username and password for the remote site that a connection is being established with. CURLOPT_NOBODY TRUE to exclude the body from the output. Request method is then set to HEAD. Changing this to FALSE does not change it to GET. CURLOPT_NOPROGRESS TRUE to disable the progress meter for cURL transfers. Note: PHP automatically sets this option to TRUE, this should only be changed for debugging purposes. CURLOPT_NOSIGNAL TRUE to ignore any cURL function that causes a signal to be sent to the PHP process. This is turned on by default in multi-threaded SAPIs so timeout options can still be used. Added in cURL 7.10. CURLOPT_PATH_AS_IS TRUE to not handle dot dot sequences. Added in cURL 7.42.0. Available since PHP 7.0.7. CURLOPT_PIPEWAIT TRUE to wait for pipelining/multiplexing. Added in cURL 7.43.0. Available since PHP 7.0.7. CURLOPT_POST TRUE to do a regular HTTP POST. This POST is the normal application/x-www-form-urlencoded kind, most commonly used by HTML forms. CURLOPT_PUT TRUE to HTTP PUT a file. The file to PUT must be set with CURLOPT_INFILE and CURLOPT_INFILESIZE. CURLOPT_RETURNTRANSFER TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it directly. CURLOPT_SAFE_UPLOAD TRUE to disable support for the @ prefix for uploading files in CURLOPT_POSTFIELDS, which means that values starting with @ can be safely passed as fields. CURLFile may be used for uploads instead. Added in PHP 5.5.0 with FALSE as the default value. PHP 5.6.0 changes the default value to TRUE. PHP 7 removes this option; the CURLFile interface must be used to upload files. CURLOPT_SASL_IR TRUE to enable sending the initial response in the first packet. Added in cURL 7.31.10. Available since PHP 7.0.7. CURLOPT_SSL_ENABLE_ALPN FALSE to disable ALPN in the SSL handshake (if the SSL backend libcurl is built to use supports it), which can be used to negotiate http2. Added in cURL 7.36.0. Available since PHP 7.0.7. CURLOPT_SSL_ENABLE_NPN FALSE to disable NPN in the SSL handshake (if the SSL backend libcurl is built to use supports it), which can be used to negotiate http2. Added in cURL 7.36.0. Available since PHP 7.0.7. CURLOPT_SSL_VERIFYPEER FALSE to stop cURL from verifying the peer's certificate. Alternate certificates to verify against can be specified with the CURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option. TRUE by default as of cURL 7.10. Default bundle installed as of cURL 7.10. CURLOPT_SSL_VERIFYSTATUS TRUE to verify the certificate's status. Added in cURL 7.41.0. Available since PHP 7.0.7. CURLOPT_TCP_FASTOPEN TRUE to enable TCP Fast Open. Added in cURL 7.49.0. Available since PHP 7.0.7. CURLOPT_TFTP_NO_OPTIONS TRUE to not send TFTP options requests. Added in cURL 7.48.0. Available since PHP 7.0.7. CURLOPT_TRANSFERTEXT TRUE to use ASCII mode for FTP transfers. For LDAP, it retrieves data in plain text instead of HTML. On Windows systems, it will not set STDOUT to binary mode. CURLOPT_UNRESTRICTED_AUTH TRUE to keep sending the username and password when following locations (using CURLOPT_FOLLOWLOCATION), even when the hostname has changed. CURLOPT_UPLOAD TRUE to prepare for an upload. CURLOPT_VERBOSE TRUE to output verbose information. Writes output to STDERR, or the file specified using CURLOPT_STDERR.

setcookie()

setcookie ( string $name [, string $value = "" [, int $expires = 0 [, string $path = "" [, string $domain = "" [, bool $secure = FALSE [, bool $httponly = FALSE ]]]]]] ) : bool setcookie ( string $name [, string $value = "" [, array $options = [] ]] ) : bool setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace. Once the cookies have been set, they can be accessed on the next page load with the $_COOKIE array. Cookie values may also exist in $_REQUEST. Parameters ¶ » RFC 6265 provides the normative reference on how each setcookie() parameter is interpreted. name The name of the cookie. value The value of the cookie. This value is stored on the clients computer; do not store sensitive information. Assuming the name is 'cookiename', this value is retrieved through $_COOKIE['cookiename'] expires The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. In other words, you'll most likely set this with the time() function plus the number of seconds before you want it to expire. Or you might use mktime(). time()+60*60*24*30 will set the cookie to expire in 30 days. If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes). Note: You may notice the expires parameter takes on a Unix timestamp, as opposed to the date format Wdy, DD-Mon-YYYY HH:MM:SS GMT, this is because PHP does this conversion internally. path The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. The default value is the current directory that the cookie is being set in. domain The (sub)domain that the cookie is available to. Setting this to a subdomain (such as 'www.example.com') will make the cookie available to that subdomain and all other sub-domains of it (i.e. w2.www.example.com). To make the cookie available to the whole domain (including all subdomains of it), simply set the value to the domain name ('example.com', in this case). Older browsers still implementing the deprecated » RFC 2109 may require a leading . to match all subdomains. secure Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client. When set to TRUE, the cookie will only be set if a secure connection exists. On the server-side, it's on the programmer to send this kind of cookie only on secure connection (e.g. with respect to $_SERVER["HTTPS"]). httponly When TRUE the cookie will be made accessible only through the HTTP protocol. This means that the cookie won't be accessible by scripting languages, such as JavaScript. It has been suggested that this setting can effectively help to reduce identity theft through XSS attacks (although it is not supported by all browsers), but that claim is often disputed. Added in PHP 5.2.0. TRUE or FALSE options An associative array which may have any of the keys expires, path, domain, secure, httponly and samesite. The values have the same meaning as described for the parameters with the same name. The value of the samesite element should be either Lax or Strict. If any of the allowed options are not given, their default values are the same as the default values of the explicit parameters. If the samesite element is omitted, no SameSite cookie attribute is set. Return Values If output exists prior to calling this function, setcookie() will fail and return FALSE. If setcookie() successfully runs, it will return TRUE. This does not indicate whether the user accepted the cookie.

fopen() modes

'r' Open for reading only; place the file pointer at the beginning of the file. 'r+' Open for reading and writing; place the file pointer at the beginning of the file. 'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. 'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate (shorten as if by cutting) the file to zero length. If the file does not exist, attempt to create it. 'a' Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. In this mode, fseek() has no effect, writes are always appended. 'a+' Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it. In this mode, fseek() only affects the reading position, writes are always appended. 'x' Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. 'x+' Create and open for reading and writing; otherwise it has the same behavior as 'x'. 'c' Open the file for writing only. If the file does not exist, it is created. If it exists, it is neither truncated (as opposed to 'w'), nor the call to this function fails (as is the case with 'x'). The file pointer is positioned on the beginning of the file. This may be useful if it's desired to get an advisory lock (see flock()) before attempting to modify the file, as using 'w' could truncate the file before the lock was obtained (if truncation is desired, ftruncate() can be used after the lock is requested). 'c+' Open the file for reading and writing; otherwise it has the same behavior as 'c'. 'e' Set close-on-exec flag on the opened file descriptor. Only available in PHP compiled on POSIX.1-2008 conform systems.

fwrite()

// $myfile = fopen( $filename, 'w' ) or die( 'unable to open the file' ); // $mytext = "Well, this is happy news!\n"; // fwrite( $myfile, $mytext ); Binary-safe file write Description fwrite ( resource $handle , string $string [, int $length ] ) : int fwrite() writes the contents of string to the file stream pointed to by handle. Parameters handle A file system pointer resource that is typically created using fopen(). string The string that is to be written. length If the length argument is given, writing will stop after length bytes have been written or the end of string is reached, whichever comes first. Note that if the length argument is given, then the magic_quotes_runtime configuration option will be ignored and no slashes will be stripped from string. Return Values fwrite() returns the number of bytes written, or FALSE on error.

chmod()

Changes file mode Description chmod ( string $filename , int $mode ) : bool Attempts to change the mode of the specified file to that given in mode. Parameters filename Path to the file. mode Note that mode is not automatically assumed to be an octal value, so to ensure the expected operation, you need to prefix mode with a zero (0). Strings such as "g+w" will not work properly. <?php chmod("/somedir/somefile", 755); // decimal; probably incorrect chmod("/somedir/somefile", "u+rwx,go+rx"); // string; incorrect chmod("/somedir/somefile", 0755); // octal; correct value of mode ?> The mode parameter consists of three octal number components specifying access restrictions for the owner, the user group in which the owner is in, and to everybody else in this order. One component can be computed by adding up the needed permissions for that target user base. Number 1 means that you grant execute rights, number 2 means that you make the file writeable, number 4 means that you make the file readable. Add up these numbers to specify needed rights. You can also read more about modes on Unix systems with 'man 1 chmod' and 'man 2 chmod'. <?php // Read and write for owner, nothing for everybody else chmod("/somedir/somefile", 0600); // Read and write for owner, read for everybody else chmod("/somedir/somefile", 0644); // Everything for owner, read and execute for others chmod("/somedir/somefile", 0755); // Everything for owner, read and execute for owner's group chmod("/somedir/somefile", 0750); ?> Return Values Returns TRUE on success or FALSE on failure.

in_array()

Checks if a value exists in an array Description in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] ) : bool Searches haystack for needle using loose comparison unless strict is set. Parameters needle The searched value. Note: If needle is a string, the comparison is done in a case-sensitive manner. haystack The array. strict If the third parameter strict is set to TRUE then the in_array() function will also check the types of the needle in the haystack. Return Values Returns TRUE if needle is found in the array, FALSE otherwise.

fclose()

Closes an open file pointer Description fclose ( resource $handle ) : bool The file pointed to by handle is closed. Parameters handle The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen(). Return Values Returns TRUE on success or FALSE on failure.

htmlentities();

Convert all applicable characters to HTML entities. htmlentities ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = ini_get("default_charset") [, bool $double_encode = TRUE ]]] ) : string This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

count()

Count all elements in an array, or something in an object Description count ( mixed $array_or_countable [, int $mode = COUNT_NORMAL ] ) : int Counts all elements in an array, or something in an object. For objects, if you have SPL installed, you can hook into count() by implementing interface Countable. The interface has exactly one method, Countable::count(), which returns the return value for the count() function. Please see the Array section of the manual for a detailed explanation of how arrays are implemented and used in PHP. Parameters array_or_countable An array or Countable object. mode If the optional mode parameter is set to COUNT_RECURSIVE (or 1), count() will recursively count the array. This is particularly useful for counting all the elements of a multidimensional array. Caution count() can detect recursion to avoid an infinite loop, but will emit an E_WARNING every time it does (in case the array contains itself more than once) and return a count higher than may be expected. Return Values Returns the number of elements in array_or_countable. When the parameter is neither an array nor an object with implemented Countable interface, 1 will be returned. There is one exception, if array_or_countable is NULL, 0 will be returned.

session_create_id()

Description session_create_id ([ string $prefix ] ) : string session_create_id() is used to create new session id for the current session. It returns collision free session id. If session is not active, collision check is omitted. Session ID is created according to php.ini settings. It is important to use the same user ID of your web server for GC task script. Otherwise, you may have permission problems especially with files save handler. Parameters prefix If prefix is specified, new session id is prefixed by prefix. Not all characters are allowed within the session id. Characters in the range a-z A-Z 0-9 , (comma) and - (minus) are allowed. Return Values session_create_id() returns new collision free session id for the current session. If it is used without active session, it omits collision check.

time()

Description time ( void ) : int Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

isset()

Determine if a variable is set and is not NULL. If a variable has been unset with unset(), it will no longer be set. isset() will return FALSE if testing a variable that has been set to NULL. Also note that a null character ("\0") is not equivalent to the PHP NULL constant. If multiple parameters are supplied then isset() will return TRUE only if all of the parameters are set. Evaluation goes from left to right and stops as soon as an unset variable is encountered. isset ( mixed $var [, mixed $... ] ) : bool Parameters var The variable to be checked. ... Another variable ... Return Values Returns TRUE if var exists and has value other than NULL. FALSE otherwise.

empty()

Determine whether a variable is considered to be empty. empty ( mixed $var ) : bool Note: Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false. Returns FALSE if var exists and has a non-empty, non-zero value. Otherwise returns TRUE. A variable is considered empty if it does not exist or if its value equals FALSE. The following values are considered to be empty: "" (an empty string) 0 (0 as an integer) 0.0 (0 as a float) "0" (0 as a string) NULL FALSE array() (an empty array) No warning is generated if the variable does not exist. That means empty() is essentially the concise equivalent to !isset($var) || $var == false.

print_r();

Displays information about a variable in a way that's readable by humans. It will also show protected and private properties of objects. Static class members will not be shown. print_r(expression, returntruefalse); expression The expression to be printed. return If you would like to capture the output of print_r(), use the return parameter. When this parameter is set to TRUE, print_r() will return the information rather than print it. Return Values If given a string, integer or float, the value itself will be printed. If given an array, values will be presented in a format that shows keys and elements. Similar notation is used for objects. When the return parameter is TRUE, this function will return a string. Otherwise, the return value is TRUE.

var_dump();

Dumps information about a variable. This function displays structured information about one or more expressions that includes its type and value. Arrays and objects are explored recursively with values indented to show structure. All public, private and protected properties of objects will be returned in the output unless the object implements a __debugInfo() method (implemented in PHP 5.6.0).

filter_var();

Filters a variable with a specified filter (tip: also check that the field is not empty maybe) filter_var ( mixed $variable [, int $filter = FILTER_DEFAULT [, mixed $options ]] ) : mixed variable Value to filter. Note that scalar values are converted to string internally before they are filtered. filter The ID of the filter to apply. The Types of filters manual page lists the available filters. If omitted, FILTER_DEFAULT will be used, which is equivalent to FILTER_UNSAFE_RAW. This will result in no filtering taking place by default. options Associative array of options or bitwise disjunction of flags. If filter accepts options, flags can be provided in "flags" field of array. For the "callback" filter, callable type should be passed. The callback must accept one argument, the value to be filtered, and return the value after filtering/sanitizing it. Return Values ¶ Returns the filtered data, or FALSE if the filter fails.

strlen()

Get string length Description strlen ( string $string ) : int Returns the length of the given string. Parameters string The string being measured for length.

filesize()

Gets the size for the given file. filesize ( string $filename ) : int

implode()

Join array elements with a glue string. implode ( string $glue , array $pieces ) : string Parameters glue Defaults to an empty string. pieces The array of strings to implode. Return Values Returns a string containing a string representation of all the array elements in the same order, with the glue string between each element.

fscokopen()

Open Internet or unix domain socket connection fsockopen ( string $hostname [, int $port = -1 [, int &$errno [, string &$errstr [, float $timeout = ini_get("default_socket_timeout") ]]]] ) : resource Initiates a socket connection to the resource specified by hostname. PHP supports targets in the Internet and Unix domains as described in List of Supported Socket Transports. A list of supported transports can also be retrieved using stream_get_transports(). The socket will by default be opened in blocking mode. You can switch it to non-blocking mode by using stream_set_blocking(). The function stream_socket_client() is similar but provides a richer set of options, including non-blocking connection and the ability to provide a stream context. Parameters ¶ hostname If OpenSSL support is installed, you may prefix the hostname with either ssl:// or tls:// to use an SSL or TLS client connection over TCP/IP to connect to the remote host. port The port number. This can be omitted and skipped with -1 for transports that do not use ports, such as unix://. errno If provided, holds the system level error number that occurred in the system-level connect() call. If the value returned in errno is 0 and the function returned FALSE, it is an indication that the error occurred before the connect() call. This is most likely due to a problem initializing the socket. errstr The error message as a string. timeout The connection timeout, in seconds. Note: If you need to set a timeout for reading/writing data over the socket, use stream_set_timeout(), as the timeout parameter to fsockopen() only applies while connecting the socket. Return Values ¶ fsockopen() returns a file pointer which may be used together with the other file functions (such as fgets(), fgetss(), fwrite(), fclose(), and feof()). If the call fails, it will return FALSE

fgets()

Returns a line from an open file Gets a line from file pointer. fgets ( resource $handle [, int $length ] ) : string Parameters handle The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()). length Reading ends when length - 1 bytes have been read, or a newline (which is included in the return value), or an EOF (whichever comes first). If no length is specified, it will keep reading from the stream until it reaches the end of the line. Note: Until PHP 4.3.0, omitting it would assume 1024 as the line length. If the majority of the lines in the file are all larger than 8KB, it is more resource efficient for your script to specify the maximum line length. Return Values Returns a string of up to length - 1 bytes read from the file pointed to by handle. If there is no more data to read in the file pointer, then FALSE is returned. If an error occurs, FALSE is returned.

func_get_args()

Returns an array comprising a function's argument list Description ¶ func_get_args ( void ) : array Gets an array of the function's argument list. This function may be used in conjunction with func_get_arg() and func_num_args() to allow user-defined functions to accept variable-length argument lists. function add() { return array_sum(func_get_args()); }

error_reporting()

Sets which PHP errors are reported Description ¶ error_reporting ([ int $level ] ) : int The error_reporting() function sets the error_reporting directive at runtime. PHP has many levels of errors, using this function sets that level for the duration (runtime) of your script. If the optional level is not set, error_reporting() will just return the current error reporting level. Parameters ¶ level The new error_reporting level. It takes on either a bitmask, or named constants. Using named constants is strongly encouraged to ensure compatibility for future versions. As error levels are added, the range of integers increases, so older integer-based error levels will not always behave as expected. The available error level constants and the actual meanings of these error levels are described in the predefined constants. Return Values ¶ Returns the old error_reporting level or the current level if no level parameter is given.

explode()

Split a string by a string. explode ( string $delimiter , string $string [, int $limit = PHP_INT_MAX ] ) : array Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter. Parameters delimiter The boundary string. string The input string. limit If limit is set and positive, the returned array will contain a maximum of limit elements with the last element containing the rest of string. If the limit parameter is negative, all components except the last -limit are returned. If the limit parameter is zero, then this is treated as 1. Note: Although implode() can, for historical reasons, accept its parameters in either order, explode() cannot. You must ensure that the delimiter argument comes before the string argument. Return Values Returns an array of strings created by splitting the string parameter on boundaries formed by the delimiter. If delimiter is an empty string (""), explode() will return FALSE. If delimiter contains a value that is not contained in string and a negative limit is used, then an empty array will be returned, otherwise an array containing string will be returned.

wordwrap()

Wraps a string to a given number of characters using a string break character. wordwrap ( string $str [, int $width = 75 [, string $break = "\n" [, bool $cut = FALSE ]]] ) : string Parameters str The input string. width The number of characters at which the string will be wrapped. break The line is broken using the optional break parameter. cut If the cut is set to TRUE, the string is always wrapped at or before the specified width. So if you have a word that is larger than the given width, it is broken apart. (See second example). When FALSE the function does not split the word even if the width is smaller than the word width.

array_diff()

array_diff ( array $array1 , array $array2 [, array $... ] ) : array Compares array1 against one or more other arrays and returns the values in array1 that are not present in any of the other arrays. Parameters array1 The array to compare from array2 An array to compare against ... More arrays to compare against Return Values Returns an array containing all the entries from array1 that are not present in any of the other arrays.

array_search()

array_search ( mixed $needle , array $haystack [, bool $strict = FALSE ] ) : mixed Searches haystack for needle. Parameters needle The searched value. Note: If needle is a string, the comparison is done in a case-sensitive manner. haystack The array. strict If the third parameter strict is set to TRUE then the array_search() function will search for identical elements in the haystack. This means it will also perform a strict type comparison of the needle in the haystack, and objects must be the same instance. Return Values Returns the key for needle if it is found in the array, FALSE otherwise. If needle is found in haystack more than once, the first matching key is returned. To return the keys for all matching values, use array_keys() with the optional search_value parameter instead.

array_sum()

array_sum ( array $array ) : number array_sum() returns the sum of values in an array. Parameters array The input array. Return Values Returns the sum of values as an integer or float; 0 if the array is empty.

feof()

checks for the end of the file. you can use it as a condition in a while loop. Tests for end-of-file on a file pointer Description feof ( resource $handle ) : bool Tests for end-of-file on a file pointer. Parameters handle The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()). Return Values Returns TRUE if the file pointer is at EOF or an error occurs (including socket timeout); otherwise returns FALSE.

htmlspecialchars();

converts special characters to HTML entities performed translations: & -> &amp; " -> &quot; ' -> &#039; or &apos; < -> &lt; > -> &gt; If the input can represent characters that are not coded in the final document character set and you wish to retain those characters (as numeric or named entities), both this function and htmlentities() (which only encodes substrings that have named entity equivalents) may be insufficient. You may have to use mb_encode_numericentity() instead

mkdir()

creates a folder in the directory wherever the script is saved. mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = FALSE [, resource $context ]]] ) : bool Attempts to create the directory specified by pathname. Parameters pathname The directory path. mode The mode is 0777 by default, which means the widest possible access. For more information on modes, read the details on the chmod() page. Note: mode is ignored on Windows. Note that you probably want to specify the mode as an octal number, which means it should have a leading zero. The mode is also modified by the current umask, which you can change using umask(). recursive Allows the creation of nested directories specified in the pathname. context Note: Context support was added with PHP 5.0.0. For a description of contexts, refer to Streams. Return Values Returns TRUE on success or FALSE on failure.

curl_close()

curl_close ( resource $ch ) : void Closes a cURL session and frees all resources. The cURL handle, ch, is also deleted. Parameters ¶ ch A cURL handle returned by curl_init(). Return Values ¶ No value is returned.

curl_error()

curl_error ( resource $ch ) : string Returns a clear text error message for the last cURL operation. Parameters ¶ ch A cURL handle returned by curl_init(). Return Values ¶ Returns the error message or '' (the empty string) if no error occurred.

curl_exec()

curl_exec ( resource $ch ) : mixed Execute the given cURL session. This function should be called after initializing a cURL session and all the options for the session are set. Parameters ¶ ch A cURL handle returned by curl_init(). Return Values ¶ Returns TRUE on success or FALSE on failure. However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, FALSE on failure. Warning This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function. Note: Note that response status codes which indicate errors (such as 404 Not found) are not regarded as failure. curl_getinfo() can be used to check for these.

curl_init()

curl_init ([ string $url = NULL ] ) : resource Initializes a new session and return a cURL handle for use with the curl_setopt(), curl_exec(), and curl_close() functions. Parameters url If provided, the CURLOPT_URL option will be set to its value. You can manually set this using the curl_setopt() function. Note: The file protocol is disabled by cURL if open_basedir is set. Return Values Returns a cURL handle on success, FALSE on errors.

curl_setopt()

curl_setopt ( resource $ch , int $option , mixed $value ) : bool Sets an option on the given cURL session handle. Parameters ch A cURL handle returned by curl_init(). option The CURLOPT_XXX option to set. value The value to be set on option.

define()

define ( string $name , mixed $value [, bool $case_insensitive = FALSE ] ) : bool Defines a named constant at runtime. Parameters name The name of the constant. Note: It is possible to define() constants with reserved or even invalid names, whose value can (only) be retrieved with constant(). However, doing so is not recommended. value The value of the constant. In PHP 5, value must be a scalar value (integer, float, string, boolean, or NULL). In PHP 7, array values are also accepted. Warning While it is possible to define resource constants, it is not recommended and may cause unpredictable behavior. case_insensitive If set to TRUE, the constant will be defined case-insensitive. The default behavior is case-sensitive; i.e. CONSTANT and Constant represent different values. Warning Defining case-insensitive constants is deprecated as of PHP 7.3.0. Note: Case-insensitive constants are stored as lower-case. Return Values Returns TRUE on success or FALSE on failure.

exec()

exec ( string $command [, array &$output [, int &$return_var ]] ) : string exec() executes the given command. Parameters ¶ command The command that will be executed. output If the output argument is present, then the specified array will be filled with every line of output from the command. Trailing whitespace, such as \n, is not included in this array. Note that if the array already contains some elements, exec() will append to the end of the array. If you do not want the function to append elements, call unset() on the array before passing it to exec(). return_var If the return_var argument is present along with the output argument, then the return status of the executed command will be written to this variable. Return Values ¶ The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function. To get the output of the executed command, be sure to set and use the output parameter.

file_exists()

file_exists ( string $filename ) : bool Checks whether a file or directory exists. Parameters ¶ filename Path to the file or directory. On windows, use //computername/share/filename or \\computername\share\filename to check files on network shares. Return Values ¶ Returns TRUE if the file or directory specified by filename exists; FALSE otherwise. Note: This function will return FALSE for symlinks pointing to non-existing files. Warning This function returns FALSE for files inaccessible due to safe mode restrictions. However these files still can be included if they are located in safe_mode_include_dir. Note: The check is done using the real UID/GID instead of the effective one. Note: Because PHP's integer type is signed and many platforms use 32bit integers, some filesystem functions may return unexpected results for files which are larger than 2GB.

intval();

get the integer value of the variable intval ( mixed $var [, int $base = 10 ] ) : int Returns the integer value of var, using the specified base for the conversion (the default is base 10). intval() should not be used on objects, as doing so will emit an E_NOTICE level error and return 1.

getimagesize()

getimagesize ( string $filename [, array &$imageinfo ] ) : array The getimagesize() function will determine the size of any supported given image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag and the correspondent HTTP content type. getimagesize() can also return some more information in imageinfo parameter. Caution This function expects filename to be a valid image file. If a non-image file is supplied, it may be incorrectly detected as an image and the function will return successfully, but the array may contain nonsensical values. Do not use getimagesize() to check that a given file is a valid image. Use a purpose-built solution such as the Fileinfo extension instead. Note: Note that JPC and JP2 are capable of having components with different bit depths. In this case, the value for "bits" is the highest bit depth encountered. Also, JP2 files may contain multiple JPEG 2000 codestreams. In this case, getimagesize() returns the values for the first codestream it encounters in the root of the file. Note: The information about icons are retrieved from the icon with the highest bitrate. Note: GIF images consist of one or more frames, where each frame may only occupy part of the image. The size of the image which is reported by getimagesize() is the overall size (read from the logical screen descriptor). Parameters filename This parameter specifies the file you wish to retrieve information about. It can reference a local file or (configuration permitting) a remote file using one of the supported streams. imageinfo This optional parameter allows you to extract some extended information from the image file. Currently, this will return the different JPG APP markers as an associative array. Some programs use these APP markers to embed text information in images. A very common one is to embed » IPTC information in the APP13 marker. You can use the iptcparse() function to parse the binary APP13 marker into something readable. Note: The imageinfo only supports JFIF files. Return Values Returns an array with up to 7 elements. Not all image types will include the channels and bits elements. Index 0 and 1 contains respectively the width and the height of the image. Note: Some formats may contain no image or may contain multiple images. In these cases, getimagesize() might not be able to properly determine the image size. getimagesize() will return zero for width and height in these cases. Index 2 is one of the IMAGETYPE_XXX constants indicating the type of the image. Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag. mime is the correspondant MIME type of the image. This information can be used to deliver images with the correct HTTP Content-type header:

http_build_query()

http_build_query — Generate URL-encoded query string Description ¶ http_build_query ( mixed $query_data [, string $numeric_prefix [, string $arg_separator [, int $enc_type = PHP_QUERY_RFC1738 ]]] ) : string Generates a URL-encoded query string from the associative (or indexed) array provided. Parameters ¶ query_data May be an array or object containing properties. If query_data is an array, it may be a simple one-dimensional structure, or an array of arrays (which in turn may contain other arrays). If query_data is an object, then only public properties will be incorporated into the result. numeric_prefix If numeric indices are used in the base array and this parameter is provided, it will be prepended to the numeric index for elements in the base array only. This is meant to allow for legal variable names when the data is decoded by PHP or another CGI application later on. arg_separator arg_separator.output is used to separate arguments but may be overridden by specifying this parameter. enc_type By default, PHP_QUERY_RFC1738. If enc_type is PHP_QUERY_RFC1738, then encoding is performed per » RFC 1738 and the application/x-www-form-urlencoded media type, which implies that spaces are encoded as plus (+) signs. If enc_type is PHP_QUERY_RFC3986, then encoding is performed according to » RFC 3986, and spaces will be percent encoded (%20). Return Values ¶ Returns a URL-encoded string.

ini_set()

ini_set ( string $varname , string $newvalue ) : string Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending. Parameters varname Not all the available options can be changed using ini_set(). There is a list of all available options in the appendix. newvalue The new value for the option. Return Values Returns the old value on success, FALSE on failure.

move_uploaded_file()

move_uploaded_file ( string $filename , string $destination ) : bool This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination. This sort of check is especially important if there is any chance that anything done with uploaded files could reveal their contents to the user, or even to other users on the same system. Parameters filename The filename of the uploaded file. destination The destination of the moved file. Return Values Returns TRUE on success. If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE. If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.

fopen()

opens a file fopen ( string $filename , string $mode [, bool $use_include_path = FALSE [, resource $context ]] ) : resource fopen() binds a named resource, specified by filename, to a stream. Parameters filename If filename is of the form "scheme://...", it is assumed to be a URL and PHP will search for a protocol handler (also known as a wrapper) for that scheme. If no wrappers for that protocol are registered, PHP will emit a notice to help you track potential problems in your script and then continue as though filename specifies a regular file. mode The mode parameter specifies the type of access you require to the stream. It may be any of the following:

phpinfo()

phpinfo ([ int $what = INFO_ALL ] ) : bool Outputs a large amount of information about the current state of PHP. This includes information about PHP compilation options and extensions, the PHP version, server information and environment (if compiled as a module), the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP License. Because every system is setup differently, phpinfo() is commonly used to check configuration settings and for available predefined variables on a given system. phpinfo() is also a valuable debugging tool as it contains all EGPCS (Environment, GET, POST, Cookie, Server) data. what The output may be customized by passing one or more of the following constants bitwise values summed together in the optional what parameter. One can also combine the respective constants or bitwise values together with the bitwise or operator.

phpinfo() options

phpinfo() options Name (constant) Value Description INFO_GENERAL 1 The configuration line, php.ini location, build date, Web Server, System and more. INFO_CREDITS 2 PHP Credits. See also phpcredits(). INFO_CONFIGURATION 4 Current Local and Master values for PHP directives. See also ini_get(). INFO_MODULES 8 Loaded modules and their respective settings. See also get_loaded_extensions(). INFO_ENVIRONMENT 16 Environment Variable information that's also available in $_ENV. INFO_VARIABLES 32 Shows all predefined variables from EGPCS (Environment, GET, POST, Cookie, Server). INFO_LICENSE 64 PHP License information. See also the » license FAQ. INFO_ALL -1 Shows all of the above.

fgetc()

reads a single character from the file Gets character from file pointer Description fgetc ( resource $handle ) : string Gets a character from the given file pointer. Parameters handle The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()). Return Values Returns a string containing a single character read from the file pointed to by handle. Returns FALSE on EOF. Warning This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

fread()

reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read EOF (end of file) is reached a packet becomes available or the socket timeout occurs (for network streams) if the stream is read buffered and it does not represent a plain file, at most one read of up to a number of bytes equal to the chunk size (usually 8192) is made; depending on the previously buffered data, the size of the returned data may be larger than the chunk size. fread ( resource $handle , int $length ) : string Parameters: handle A file system pointer resource that is typically created using fopen(). length Up to length number of bytes read. Return Values Returns the read string or FALSE on failure. if you pass filesize() function as how much of the file to read, it will read the whole file.

mail();

sends an email: mail ( string $to , string $subject , string $message [, mixed $additional_headers [, string $additional_parameters ]] ) : bool $to - receiver or receivers of the email, formatting of this string must comply with RFC 2822 (comma separated if multiple) $subject - subject of the email to be sent $message - the body of the email. Each line should be separated with a CRLF (\r\n). Lines should not be larger than 70 characters. $additional_headers - if you send html you need to include content-type, also you can include from:, reply-to, returns TRUE if email was sent, returns FALSE if email wasn't sent. put it in a variable to check if true or false.t

session_destroy()

session_destroy ( void ) : bool session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called. Note: You do not have to call session_destroy() from usual code. Cleanup $_SESSION array rather than destroying session data. In order to kill the session altogether, the session ID must also be unset. If a cookie is used to propagate the session ID (default behavior), then the session cookie must be deleted. setcookie() may be used for that. When session.use_strict_mode is enabled. You do not have to remove obsolete session ID cookie because session module will not accept session ID cookie when there is no data associated to the session ID and set new session ID cookie. Enabling session.use_strict_mode is recommended for all sites. Warning Immediate session deletion may cause unwanted results. When there is concurrent requests, other connections may see sudden session data loss. e.g. Requests from JavaScript and/or requests from URL links. Although current session module does not accept empty session ID cookie, but immediate session deletion may result in empty session ID cookie due to client(browser) side race condition. This will result that the client creates many session ID needlessly. To avoid these, you must set deletion time-stamp to $_SESSION and reject access while later. Or make sure your application does not have concurrent requests. This applies to session_regenerate_id() also. Return Values Returns TRUE on success or FALSE on failure.

session_start()

session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie. session_start ([ array $options = array() ] ) : bool When session_start() is called or when a session auto starts, PHP will call the open and read session save handlers. These will either be a built-in save handler provided by default or by PHP extensions (such as SQLite or Memcached); or can be custom handler as defined by session_set_save_handler(). The read callback will retrieve any existing session data (stored in a special serialized format) and will be unserialized and used to automatically populate the $_SESSION superglobal when the read callback returns the saved session data back to PHP session handling. To use a named session, call session_name() before calling session_start(). When session.use_trans_sid is enabled, the session_start() function will register an internal output handler for URL rewriting. If a user uses ob_gzhandler or similar with ob_start(), the function order is important for proper output. For example, ob_gzhandler must be registered before starting the session. options If provided, this is an associative array of options that will override the currently set session configuration directives. The keys should not include the session. prefix. In addition to the normal set of configuration directives, a read_and_close option may also be provided. If set to TRUE, this will result in the session being closed immediately after being read, thereby avoiding unnecessary locking if the session data won't be changed. Return Values ¶ This function returns TRUE if a session was successfully started, otherwise FALSE.

session_unset()

session_unset — Free all session variables Description session_unset ( void ) : bool The session_unset() function frees all session variables currently registered. Return Values Returns TRUE on success or FALSE on failure.

unset()

unset() destroys the specified variables. The behavior of unset() inside of a function can vary depending on what type of variable you are attempting to destroy. If a globalized variable is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called. unset ( mixed $var [, mixed $... ] ) : void To unset() a global variable inside of a function, then use the $GLOBALS array to do so.


Related study sets

MW Theory Paper 2 - Vinification and Pre-Bottling Procedures

View Set

S & L Chapter 31: The Nurse in the Schools

View Set

Chapter 16- Innate Immunity: Nonspecific Defenses of the Host

View Set

Accounting chapter 17 special journals: purchases an cash payments

View Set

Trigonometric Graphs (Precalculus)

View Set

Series 7: Unit 5--Corporate Bonds

View Set

Completa Oracion con el Verbo/ El imperativo Informal

View Set