HOW THE QUIZ WORKS:
Clicking the ‘randomize’ button situated above the reference table generates a new table whereby the function descriptions, function syntaxes, and function return values are randomized. The quiz involves matching the function descriptions, function syntaxes, and function return values to the correct function name. Information relating to the randomization of table cells will be displayed for three seconds, before disappearing.
On a desktop computer, table elements are selected by left-clicking the desired table cell and holding the left click in the mouse down position for one second before releasing the left click. The text inside the table cell will turn red to indicate that the one-second mouse left-click has successfully selected a table cell. To then swap the selected table cell with the target table cell, simply repeat the one-second left mouse-click process on the target cell; the table cells will swap position. To de-select a table cell, simply repeat the one-second left mouse-click process on the original table cell.
To select a table element on a touchscreen device (mobile, tablet), simply touch the desired table cell and maintain the touch for one second before removing your finger from the screen. The text inside the table cell will turn red to indicate that the one-second touch has successfully selected a table cell. To then swap the selected table cell with the target table cell, simply repeat the one-second touch process on the target cell; the table cells will swap position. To de-select a table cell, simply repeat the one-second touch process on the original table cell.
Normal touchscreen scrolling behaviour is exhibited by the cells with a light green background; cells without a light green background will not respond to normal touchscreen scrolling. The table is positioned in such a way that the user can also initiate touchscreen scrolling by swiping to the right or left of the table.
When a row consists of the correct function name, function description, function syntax, and function return value, the background colour of the row will change from ‘transparent’ to ‘khaki’; this provides visual feedback that the row is complete.
Once the entire table is complete, a paragraph of feedback will congratulate the user and provide the following information: date and time of quiz commencement; date and time of quiz completion; and the length of time it took the user to complete the quiz.
VIEWPORT OPTIONS:



PURPOSE:
This webpage serves two purposes:
- It provides a reference table for the PHP string functions, with information extracted and condensed from w3schools.com and php.net.
- It enables users to complete a quiz related to the PHP string functions.
USAGE:
For each string function there are four table cells of information: the function name; the function description; the function syntax; and the function return value. There are three layouts available – ‘mobile‘, ‘tablet‘, and ‘desktop‘.
Click the relevant button below to display the PHP string functions reference table, sized appropriately for the desired viewport. A ‘RANDOMIZE‘ button appears above the reference table once the viewport is selected; clicking this button facilitates the commencement of a quiz.
Click the ‘RANDOMIZE‘ button to randomize the functional descriptions, the functional syntaxes, and the functional return information.
FUNCTION NAME | FUNCTION DESCRIPTION | FUNCTION SYNTAX | FUNCTION RETURN VALUE |
---|---|---|---|
addcslashes()
[Quote string with slashes in a C style] |
Returns a string with backslashes added before characters that are listed in charlist. | addcslashes(string, charlist); |
addcslashes() : Returns the escaped string. |
addslashes()
[Quote string with slashes] |
Returns a string with backslashes added before characters that need to be escaped [single quote; double quote; backslash; NUL]. | addslashes(string);
[Prior to PHP 5.4.0, the PHP directive |
addslashes() : Returns the escaped string. |
bin2hex()
[Convert binary data into hexadecimal representation] |
Returns an ASCII string containing the hexadecimal representation of string. The conversion is done byte-wise with the high nibble first. | bin2hex(string); |
bin2hex() : returns the hexadecimal representation of string. |
rtrim()
[Strip whitespace (or other characters) from the end of a string] |
Returns a string with whitespace (or other characters) trimmed from the end of string. This function is an alias of chop() . |
rtrim(string, character_mask [optional parameter]);
[Without the optional character_mask parameter, |
rtrim() : returns the modified string. |
chr()
[Generate a single-byte string from a number] |
Returns a one-character string containing the character specified by interpreting bytevalue as an unsigned integer. Used with single-byte encodings such as ASCII, ISO-8859, and Windows 1252; cannot be passed a Unicode code point value to generate a string in a multibyte encoding such as UTF-8 or UTF-16. |
chr(bytevalue);
[bytevalue must be an integer in the range 0-255. If an integer less than 0 is passed, 256 is continuously added to the integer until it falls within the 0-255 range. bytevalue is then taken to be equal to the remainder of bytevalue divided by 256.] |
chr() : returns a single-character string containing the specified byte. |
chunk_split()
[Split a string into smaller chunks] |
Can be used to split a string into smaller chunks; this is useful for converting base64_encode() output to match RFC 2045 semantics.It inserts end every chunklen characters. |
chunk_split(string, chunklen [optional parameter, default length is 76], end [optional parameter, default line ending is “\r\n”]); |
chunk_split() : returns the chunked string. |
convert_cyr_string()
[Convert from one Cyrillic character set to another] |
This function converts string from one Cyrillic character set to another. | convert_cyr_string(string, from, to);
[from and to represent a Cyrillic character set with a single-character denotation. Possible representations include: k = k-oi8-r; w = windows-1251; i = iso-8859-5; a = x-cp866; d = x-cp866; m = x-mac-cyrillic. |
convert_cyr_string() : returns the converted string. |
convert_uudecode()
[Decode a uuencoded string] |
This function decodes a uuencoded string. convert_uudecode() accepts neither the begin nor the end line, which are part of uuencoded files. |
convert_uudecode(data_string); |
convert_uudecode() : returns the decoded data as a string on success; FALSE on failure. |
convert_uuencode()
[Uuencode a string] |
This function encodes a string using the uuencode algorithm. Uuencode translates all strings – including binary data – into printable characters, thus rendering them safe for network transmissions. Uuencoded data is about 35% larger than the original. convert_uuencode neither produces the begin nor the end line, which are part of uuencoded files. |
convert_uuencode(data_string); |
convert_uuencode() : returns the uuencoded data on success; FALSE on failure. |
count_chars()
[Return information about characters used in a string] |
Counts the number of occurrences of every byte-value [0-255] in string and returns it in various ways. | count_chars(string, mode [optional parameter – default is 0]); |
count_chars() : return value is dependent upon mode parameter: if omitted or 0 – an array with the byte value as key and the number of occurrences as value; if 1 – same as 0, but only byte-values with a frequency greater than 0 are listed; if 2 – same as 0 but only byte-values with a frequency of 0 are listed; if 3 – a string containing all unique characters is returned; if 4 – a string containing all unused characters is returned. |
crc32()
[Calculates the crc32 polynomial of a string] |
Generates the cyclic redundancy checksum polynomial of 32-bit lengths of the string. Usually used to validate the integrity of data being transmitted. | crc32(string); |
crc32() : returns the crc32 checksum of string as an integer. |
crypt()
[One-way string hashing] |
crypt() will return a hashed string using the standard Unix DES-based algorithm or alternative algorithms that may be available on the system. Although salt is optional, crypt() creates a weak hash without it. PHP 5.6+ raises an E_NOTICE error without salt. password_hash() – a simple crypt wrapper – uses a strong hash, generates a strong salt, and applies proper rounds automatically; its use is encouraged. |
crypt(string, salt [optional parameter]); |
crypt() : returns the hashed string on success or a string that is shorter than 13 characters and is guaranteed to differ from the salt on FAILURE.When validating passwords, a string comparison function that isn’t vulnerable to timing attacks should be used to compare the output of crypt() to the previously-known hash — PHP 5.6+ provides hash_equals() for this purpose. |
echo()
[Output one or more strings] |
Outputs [‘echoes’] all parameters; no newline is appended. If you want to pass more than one parameter to echo() , the parameters must not be enclosed within parentheses. Unlike print , echo() accepts an argument list and has no return value. |
Standard Syntax:echo(string_1, string_2 …[optional parameter]); Shortcut Syntax [since PHP 5.4.0 / any PHP version with short_open_tag enabled]:<?=$string?> |
echo() : No value is returned. |
explode()
[Split a string by a string] |
Returns an array of strings, each of which is a substring of string created by splitting (‘exploding’) it on boundaries formed by the string delimiter. | explode(delimiter, string, limit [optional parameter with a default value of PHP_INT_MAX ] );
[If limit is positive, the returned array will contain a maximum of limit elements – with the last element containing the rest of string. If limit is negative, the returned array contains all but –limit components. If the limit parameter is 0, this is treated as 1.] |
explode() : returns an array of strings created by splitting [‘exploding’] string by the boundaries formed by delimiter. explode() will return FALSE if delimiter is an empty string. If delimiter represents a value that is not contained in string AND a negative limit is used, this function returns an empty array; otherwise, an array containing string will be returned. |
fprintf()
[Write a formatted string to a stream] |
This function writes a string produced according to format to the stream resource specified by handle. | fprintf(resource_handle, format, args [optional parameter – arguments can be passed to this function]); |
fprintf() : returns the number of bytes written to the resource stream. |
get_html_translation_table()
[Returns the translation table used by |
Returns the translation table that is used internally for htmlspecialchars and htmlentities. |
get_html_translation_table(table [optional parameter, default is HTML_SPECIALCHARS], flags [optional parameter, default is ENT_COMPAT|ENT_HTML401], encoding [optional parameter, default is “UTF_8” in PHP 5.4.0+; was ISO-8859-1 prior to PHP 5.4.0]);
[table can be either HTML_ENTITIES or HTML_SPECIALCHARS. |
get_html_translation_table() : returns the translation table as an array, with the original characters as keys and the entities as values. |
hebrev()
[Convert logical hebrew text to visual text] |
This function tries to avoid breaking words while converting logical hebrew_text to visual text. | hebrev(hebrew_text, max_chars_per_line [optional parameter, default of 0]); |
hebrev() : returns the visual string conversion of hebrew_text. |
hebrevc()
[Convert logical hebrew text to visual text with newline conversion] |
This function tries to avoid breaking words while converting logical hebrew_text to visual text and converting newlines (\n ) to <br/>\n . |
hebrevc(hebrew_text, max_chars_per_line [optional parameter, default of 0]); |
hebrevc() : returns the visual string conversion of hebrew_text. |
hex2bin()
[Decodes a hexadecimally-encoded binary string] |
This function decodes a hexadecimally-encoded binary string. It does NOT convert a hexadecimal number to a binary number – this can be done using base_convert() . |
hex2bin(data_string); |
hex2bin() : returns the binary representation of data_string on success; FALSE on failure. If data_string is of an odd length or is an invalid hexadecimal string, an E_WARNING-level error is thrown. |
html_entity_decode()
[Convert HTML entities to their corresponding characters] |
Insofar as it decodes HTML entities in string to their corresponding characters, this function achieves the opposite of htmlentities() . This function decodes all the entities that are necessarily valid for the chosen document type and whose character(s) are in the coded character set associated with the chosen encoding and are permitted in the chosen document type; all other entities are left as-is. |
html_entity_decode(string, flags [optional parameter, default = ENT_COMPAT|ENT_HTML401], encoding [optional parameter, default = ini_get("default_charset") ; was ISO-8859-1 previously]);
[for more information about flags and encoding, see the |
html_entity_decode() : returns the decoded string. |
htmlentities()
[Convert all applicable characters to HTML entities] |
This function provides the same functionality as htmlspecialchars() , as well as translating all characters that have HTML character entity equivalents into those entities. |
htmlentities(string, flags [optional parameter, default value of ENT_COMPAT|ENT_HTML401], encoding [optional parameter, default value of ini_get(“default_charset”) in PHP 5.6+; PHP 5.4, PHP 5.5 default = UTF-8; default of earlier versions was ISO-8859-1], double_encode [optional parameter, default value of TRUE]);
[For more information about encoding see the |
htmlentities() : returns the encoded string on success. If string contains an invalid code unit sequence an empty string will be returned unless either the ENT_IGNORE or ENT_SUBSTITUTE flags are set. |
htmlspecialchars_decode()
[Convert special HTML entities back to characters] |
This function converts HTML entities back to characters; it does the opposite of the htmlspecialchars() function. The following entities are decoded: ampersand; double quote (when ENT_NOQUOTES is not set); single quote (when ENT_QUOTES is set); ‘less than’ sign; and the ‘greater than’ sign. |
htmlspecialchars_decode(string, flags [optional parameter, default value is ENT_COMPAT|ENT_HTML401]);
[The flags parameter can be any of the following values: ENT_COMPAT; ENT_QUOTES; ENT_NOQUOTES; ENT_HTML401; ENT_XML1; ENT_XHTML; or ENT_HTML5.] |
htmlspecialchars_decode() : returns the decoded string. |
htmlspecialchars()
[Convert special characters to HTML entities] |
This function returns a string with certain characters – that have a special meaning in HTML – converted to entities. The following characters will be translated: ampersand; double quote; single quote; ‘less than’ sign; and the ‘greater than’ sign. | htmlspecialchars(string, flags [optional parameter, default value of ENT_COMPAT|ENT_HTML401], encoding [optional parameter, default value of ini_get(“default_charset”)], double_encode [optional parameter, default value of TRUE]); |
htmlspecialchars() : returns the converted string. An empty string will be returned if string contains an invalid code unit sequence within the given encoding, unless either the ENT_IGNORE or ENT_SUBSTITUTE flags are set. |
implode()
[Join array elements with a string] |
This function condenses [‘implodes’] pieces_array into a string, compressing the array elements with glue_string. glue_string defaults to an empty string. This function is an alias of join() . |
implode(glue_string [optional parameter, with a default value of an empty string], pieces_array); |
implode() : returns a string containing a string representation of the imploded array, with glue_string between each element. |
lcfirst()
[Make a string’s first character lowercase] |
Returns a string with the first character of string lowercased if that character is ‘alphabetic’. ‘Alphabetic’ is determined with reference to the current locale; in the default ‘C’ locale, characters such as umlaut-a will not be converted. | lcfirst(string); |
lcfirst() : returns string with its first character lowercased if the character is deemed ‘alphabetic’; otherwise it returns the input string. |
levenshtein()
[Calculate Levenshtein distance between two strings] |
The Levenshtein distance is defined as the minimum number of characters you have to replace, insert, or delete to transform string_1 into string_2. The simplest form of the function just calculates the number of replace, insert, or delete operations needed to transform string_1 into string_2. A more general and adaptive – but less efficient – variant takes three extra parameters that define the cost of replace, insert, and delete operations. | Variant One:levenshtein(string_1, string_2); Variant Two: levenshtein(string_1, string_2, insert_cost, replace_cost, delete_cost); |
levenshtein() : returns the Levenshtein-Distance between string_1 and string_2 OR -1 if one of the strings is longer than 255 characters. |
localeconv()
[Get numeric formatting information] |
Returns an associative array containing localized numeric and monetary formatting information. Returns data based on the current locale as defined by setlocale() . |
localeconv(); |
localeconv() : returns an associative array containing locale-specific numeric formatting information. Elements comprise: ‘decimal_point’; ‘thousands_sep’; ‘grouping’; ‘int_curr_symbol’; ‘currency_symbol’; ‘mon_decimal_point’; ‘mon_thousands_sep’; ‘mon_grouping’; ‘positive_sign’; ‘negative_sign’; ‘int_frac_digits’; ‘frac_digits’; ‘p_cs_precedes’; ‘p_sep_by_space’; ‘n_cs_precedes’; ‘n_sep_by_space’; ‘p_sign_posn’; and ‘n_sign_posn’. |
ltrim()
[Strip whitespace (or other characters) from the beginning of a string] |
This function strips (‘trims’) whitespace (or other characters) from the beginning (left-hand side) of string. | ltrim(string, character_mask [optional parameter – simply list all the characters you want stripped; using ‘..’ defines a range]); |
ltrim() : returns a string with whitespace (and any other characters specified in character_mask) trimmed from the start of string.If no further characters are specified in the character_mask parameter, ltrim() will strip the following characters: an ordinary space; a tab; a newline; a carriage return; the NUL-byte; and a vertical tab. |
md5_file()
[Calculates the md5 hash of a given file] |
Calculates the MD5 hash of the specified file, using the RSA Data Security, Inc. MD5 Message-Digest Algorithm, and returns that hash [a 32-character hexadecimal number]. | md5_file(file, raw_output [optional parameter, with a default value of FALSE]);
[When raw_output is TRUE, the digest is returned in raw binary format with a length of 16.] |
md5_file() : returns a string on success; FALSE otherwise. |
md5()
[Calculate the md5 hash of a string] |
Calculates the MD5 hash of string, using the RSA Data Security, Inc. MD5 Message-Digest Algorithm, and returns that hash. Owing to the fast nature of the hashing algorithm, it is not recommended to use this function to secure passwords. | md5(string, raw_output [optional parameter, with a default value of FALSE]);
[If raw_output is set to TRUE, the md5 digest is returned in raw binary format with a length of 16.] |
md5() : returns the MD5 hash of string. |
metaphone()
[Calculate the metaphone key of a string] |
Calculates the metaphone key of string. Similar to soundex() , but more accurate since it knows the basic rules of English pronunciation. The metaphone-generated keys are of variable length. |
metaphone(string, phonemes [optional parameter, defaulting to 0 – meaning ‘no restriction’]); |
metaphone() : returns the metaphone key as a string on success; FALSE on failure. |
money_format()
[Formats a number as a currency string] |
This function returns a monetarily–formatted version of number. It wraps the C library function strfmon() , with the difference that this function converts only one number at a time; this function is only defined on systems that implement strfmon capabilities. |
money_format(format, number);
[The format sequence is as follows: a percentage character — optional flags — optional field width — optional left precision — optional right precision — a required conversion character.] |
money_format() : returns the monetarily–formatted string. Characters preceding and succeeding the format string will be returned unchanged. A non-numeric number causes NULL to be returned and an E_WARNING to be emitted. |
nl_langinfo()
[Query language and locale information] |
nl_langinfo() is used to access individual elements of the locale categories; it allows you to select any specific element. |
nl_langinfo(item);
[item may be an integer value of the element or the constant name of the element. The following constant names can be used: ABDAY_(1-7); DAY_(1-7); ABMON_(1-12); MON_(1-12); AM_STR; PM_STR; D_T_FMT; D_FMT; T_FMT; T_FMT_AMPM; ERA; ERA_YEAR; ERA_D_T_FMT; ERA_D_FMT; ERA_T_FMT; INT_CURR_SYMBOL; CURRENCY_SYMBOL; CRNCYSTR; MON_DECIMAL_POINT; MON_THOUSANDS_SEP; MON_GROUPING; POSITIVE_SIGN; NEGATIVE_SIGN; INT_FRAC_DIGITS; FRAC_DIGITS; P_CS_PRECEDES; P_SEP_BY_SPACE; N_CS_PRECEDES; N_SEP_BY_SPACE; P_SIGN_POSN; N_SIGN_POSN; DECIMAL_POINT; RADIXCHAR; THOUSANDS_SEP; THOUSEP; GROUPING; YESEXPR; NOEXPR; YESSTR; NOSTR; or CODESET.] |
nl_langinfo() : returns the element as a string; FALSE on failure. |
nl2br()
[Inserts HTML line breaks before all newlines in a string] |
Returns string with <br/> or <br> inserted before all newlines [\r\n,\n\r,\n,\r]. | nl2br(string, is_xhtml [optional parameter, specifying whether to use XHTML-compatible line breaks or not – default is TRUE]); |
nl2br() : returns string with HTML line breaks inserted before all newlines. |
number_format()
[Format a number with grouped thousands] |
In formatting a number with grouped thousands, this function accepts 1, 2, or 4 parameters. If only 1 parameter is given, number will be formatted without decimals, but with a comma between every group of thousands. If two parameters are given, number will be formatted with decimals decimals with a dot in front, and a comma between each group of thousands. If all four parameters are given, number will be formatted with decimals decimals, dec_point instead of a dot before the decimals, and thousands_sep instead of a comma between each group of thousands. | 1- or 2-parameter syntax:number_format(number, decimals [optional parameter, with a default value of 0]); 4-parameter syntax: number_format(number, decimals, dec_point, thousands_sep); |
number_format() : returns the formatted version of number. |
ord()
[Convert the first byte of a string to a value between 0 and 255] |
This function interprets the binary value of the first byte of string as an unsigned integer in the range 0-255. This function is not aware of any string encoding; it will never identify a Unicode code point in a multi-byte encoding such as UTF-8 or UTF-16. If string is in a single-byte encoding – for example, ASCII, ISO-8859, or Windows 1252 – this is equivalent to returning the position of a character in the character set’s mapping table. | ord(string); |
ord() : returns an integer between 0-255, representing the binary value of the first byte of string. |
parse_str()
[Parses the string into variables] |
Parses encoded_string as if it were the query string passed via a URL and sets variables in the current scope [or in result_array, if provided]. | parse_str(encoded_string, result_array [optional parameter, in which the parsed string variables will be stored]);
[Omission of the result_array is strongly discouraged and deprecated as of PHP 7.2.] |
parse_str() : no value is returned [void]. |
print()
[Output a string] |
This function outputs [‘prints’] arg. Parentheses are not required, since it is a language construct rather than a function. Similar to echo but only accepts a single argument, and always returns 1. |
print(arg); |
print() : always returns 1. |
printf()
[Output a formatted string] |
Produces [‘prints’] output according to format. | printf(format, args [an optional number of parameters to be output according to format]); |
printf() : returns the length of the outputted string. |
quoted_printable_decode()
[Convert a quoted printable string to an 8 bit string] |
This function – similar to imap_qprint() , except this one does not require the IMAP module to work – returns an 8-bit binary string corresponding to the decoded quoted printable string [according to RFC2045, section 6.7.] |
quoted_printable_decode(string); |
quoted_printable_decode() : returns the 8-bit binary string representation of string. |
quoted_printable_encode()
[Convert a 8 bit string to a quoted printable string] |
This function – similar to imap_8bit() except it does not require the IMAP module to work – converts an 8-bit string to a quoted printable string created according to RFC2045 Section 6.7. |
quoted_printable_encode(string); |
quoted_printable_encode() : returns the encoded string. |
quotemeta()
[Quote meta characters] |
Returns a version of string with a backslash character [\] in front of the following characters: .\+*?[^]($). Thus, it quotes the meta characters. |
quotemeta(string); |
quotemeta() : returns the string with meta characters quoted on success; FALSE if an empty string is passed to the function. |
setlocale()
[Sets locale information] |
This function sets locale information. | With locale as string:setlocale(category, locale_string [1 or more optional parameters to try as locale settings until success]); With locale as array: setlocale(category, locale_array [each array element will be used in an attempt to set the locale until one is successful]);
[category is a named constant specifying the category of the functions affected by the locale setting. The following seven named constants are permissible: LC_ALL; LC_COLLATE; LC_CTYPE; LC_MONETARY; LC_NUMERIC; LC_TIME; or LC_MESSAGES. |
setlocale() : returns the new current locale on success, or FALSE if the locale functionality is not implemented on your platform, the specified locale does not exist, or the category name is invalid. An invalid category name also causes a WARNING message. |
sha1_file()
[Calculate the sha1 hash of a file] |
Calculates and returns the sha1 hash of the file specified by filename using the US Secure Hash Algorithm 1. The hash is a forty-character hexadecimal number. | sha1_file(filename, raw_output [optional parameter, defaults to FALSE]);
[If raw_output is set to TRUE the digest is returned in raw binary format with a length of twenty.] |
sha1_file() : returns the sha1 hash of the file specified by filename on success; FALSE on failure. |
sha1()
[Calculate the sha1 hash of a string] |
This function calculates the sha1 hash of string, using the US Secure Hash Algorithm 1. | sha1(string, raw_output [optional parameter with a default value of FALSE]);
[If raw_output is set to TRUE, the sha1 digest is instead returned in raw binary format with a length of 20; otherwise the returned value is a 40-character hexadecimal number.] |
sha1() : returns the sha1 hash as a string. |
similar_text()
[Calculate the similarity between two strings] |
This function calculates the similarity of string_1 and string_2 [two ‘texts’]. | similar_text(string_1, string_2, percentage [optional parameter – passing a reference as the third parameter stores the similarity in percent, by dividing the result of similar_text() by the average length of the given strings (similar_text() /((string_1_length + string_2_length)/2) * 100)]);
[The number of matching characters is calculated by finding the longest first common substring, and then doing this for the prefixes and the suffixes, recursively. The lengths of all common substrings are added.] |
similar_text() : returns the number of matching chars in both strings. |
soundex()
[Calculate the soundex key of a string] |
Calculates the soundex key of string. Words pronounced similarly produce the same soundex key, and can therefore be used to simplify searching databases where you know the pronunciation but not the spelling. This implementation of the soundex function returns a string 4 characters long, starting with a letter. | soundex(string); |
soundex() : returns the soundex key as string. |
sprintf()
[Return a formatted string] |
This function returns a string produced according to format_string. | sprintf(format_string, args... [optional parameters that will be formatted according to format_string]);
[The format_string is composed of zero or more directives: ordinary characters that are copied directly to the result and conversion specifications, each of which results in fetching its own parameter. Each conversion specification contains a percentage sign followed by one or more of the following elements, in sequence: sign specifier; padding specifier; alignment specifier; width specifier; precision specifier; and a type specifier.] |
sprintf() : returns a string produced according to format_string on success; FALSE on failure. |
sscanf()
[Parses input from a string according to a format] |
This function reads [‘scans’] from string and interprets it according to format. Any whitespace in format [even a tab \t] matches any whitespace in string. | sscanf(string, format, args... [optionally pass in variables by reference that will contain the parsed values]); |
sscanf() : if only two parameters were present, the values parsed will be returned as an array. If optional parameters are passed, the function will return the number of assigned values. If more substrings are expected in format than are available within string, -1 will be returned. |
str_getcsv()
[Parse a CSV string into an array] |
This function parses input_string for fields in CSV format and returns an array containing the fields read. Take care with locale settings when using this function – strings in one-byte encodings may be read incorrectly if LC_CTYPE is set to en_US.UTF-8, for example. | str_getcsv(input_string, delimiter [optional single-character parameter, default is “,“], enclosure [optional single-character parameter, default is ‘“‘], escape_character [optional single-character parameter, default is “\“]); |
str_getcsv() : returns an indexed array containing the fields read. |
str_ireplace()
[Case-insensitive version of |
This function returns a string or an array with all case-insensitive occurrences of search in subject replaced with the given replace value. | str_ireplace(search, replace, subject, count [optional parameter – if passed, this will be set to the number of replacements performed]);
[Search and replace rules: if search and replace are arrays, a value is taken from each array and used to search-and-replace on subject; if replace has fewer values than search, an empty string is used for the rest of replacement values; if search is an array and replace is a string, then this replacement string is used for every value of search; if search or replace are arrays, their elements are processed first to last.] |
str_ireplace() : returns a string or an array of replacements. |
str_pad()
[Pad a string to a certain length with another string] |
This function returns input_string padded on the left, the right, or on both sides to the specified pad_length. If pad_string is not supplied, input_string is padded with spaces; otherwise it is padded with characters from pad_string up to the limit. | str_pad(input_string, pad_length, pad_string [optional parameter – default is whitespace “ “], pad_type [optional parameter – default value is STR_PAD_RIGHT]);
[If pad_length is negative, less than or equal to the length of input_string, no padding takes place and input_string will be returned. The pad_string may be truncated if the required number of padding characters cannot be evenly divided by the pad_string‘s length. pad_type can be any of the following values: STR_PAD_RIGHT; STR_PAD_LEFT; or STR_PAD_BOTH] |
str_pad() : returns the padded string. |
str_repeat()
[Repeat a string] |
This function returns input_string repeated multiplier times. | str_repeat(input_string, multiplier);
[multiplier must be greater than or equal to 0. If 0, an empty string will be returned.] |
str_repeat() : returns input_string repeated multiplier times. |
str_replace()
[Replace all occurrences of the search string with the replacement string] |
This function returns a string or an array with all case-sensitive occurrences of search in subject replaced with the given replace value. | str_replace(search, replace, subject, count [optional parameter – if present, it will be set to the number of replacements performed]);
[The same search-and-replace rules apply for this function as for |
str_replace() : returns a string or an array with the replaced values. |
str_rot13()
[Perform the rot13 transform on a string] |
This function performs the ROT13 encoding on string and returns the resulting string. The ROT13 encoding simply shifts every letter by 13 places in the alphabet; non-alpha characters are left untouched. Since encoding and decoding are done by the same function, passing an encoded string as argument will return the original version. | str_rot13(string); |
str_rot13() : returns the ROT13 version of string. |
str_shuffle()
[Randomly shuffles a string] |
This function shuffles string. One permutation out of all possible is created. This function should not be used for cryptographic purposes; random_int() , random_bytes() , or openssl_random_pseudo_bytes() should be used instead. |
str_shuffle(string); |
str_shuffle() : returns the shuffled string. The internal randomization algorithm has been changed to use the Mersenne-Twister Random Number Generator rather than the libc rand function. |
str_split()
[Convert a string to an array] |
This function splits a string into an array. | str_split(string, split_length [optional parameter with a default value of 1]); |
str_split() : if the split_length parameter is specified, the returned array will be broken down into chunks with each chunk being split_length in length; otherwise, each chunk will be one character in length. If split_length is less than 1, FALSE is returned. If split_length exceeds the length of string, the entire string is returned as the first – and only – array element. |
str_word_count()
[Return information about words used in a string] |
This function counts the number of words inside string. If format is not specified the return value will be an integer representation of the number of words found inside string. If format is specified, the return value will be an array. For this function, ‘word’ is defined as a locale-dependent string containing alphabetic characters; ‘word’ may contain – but not start with – “‘” and “–” characters. | str_word_count(string, format [optional parameter with a default value of 0], charlist [optional parameter]);
[format can be one of three values: 0 [default – returns the number of words found]; 1 [returns an array of all the words found inside string]; or 2 [returns an associative array, where the key is the numeric position of the word inside string, and the value is the word itself.] charlist represents a list of additional characters which will be considered as a valid unit of ‘word’.] |
str_word_count() : returns an array or an integer, depending on the format chosen. |
strcasecmp()
[Binary safe case-insensitive string comparison] |
This function performs a binary-safe case-insensitive string comparison. | strcasecmp(string_1, string_2); |
strcasecmp() : returns an integer – <0 if string_1 is less than string_2; >0 if string_1 is greater than string_2; or 0 if string_1 and string_2 are equal. |
strstr()
[Find the first occurrence of a string] |
This function – an alias of strchr() – returns part of haystack starting from – and including – the first occurrence of needle string to the end of haystack string. Unlike stristr() , this function is case-sensitive. To simply determine the presence of needle within haystack, the use of strpos() is recommended since it is faster and less memory-intensive. |
strstr(haystack, needle, before_needle [optional parameter, with a default value of FALSE]);
[If needle is not a string, it is converted to an integer and used as the ordinal value of a character. If before_needle is set to TRUE, the first part of haystack is returned [up to – but excluding – needle].] |
strstr() : returns the portion of string, or FALSE if needle is not found. |
strcmp()
[Binary safe string comparison] |
This function performs a binary-safe case-sensitive string comparison. | strcmp(string_1, string_2); |
strcmp() : returns <0 if string_1 is less than string_2; 0 if string_1 is equal to string_2; >0 if string_1 is greater than string_2. |
strcoll()
[Locale based string comparison] |
This function uses the current locale to perform a case-sensitive string comparison. If the current locale is C or POSIX, this function is equivalent to strcmp() . |
strcoll(string_1, string_2); |
strcoll() : returns <0 if string_1 is less than string_2; 0 if string_1 is equal to string_2; >0 if string_1 is greater than string_2. |
strcspn()
[Find length of initial segment not matching mask] |
This function returns the length [‘span‘] of the initial segment of the string subject which does not contain any of the characters in mask. | strcspn(subject, mask, start [optional parameter], length [optional parameter]);
[start represents the position in subject to start searching. If start is given and is non-negative, |
strcspn() : returns the length of the initial segment of subject which consists entirely of characters not in mask. When a start parameter is set, the returned length is counted from this start position, not from the beginning of subject. |
strip_tags()
[Strip HTML and PHP tags from a string] |
This function tries to return a string with all NULL bytes, HTML and PHP tags stripped from a given string. It uses the same tag-stripping state machine as fgetss() . HTML comments and PHP tags are automatically stripped out; this cannot be changed with allowable_tags. In PHP 5.3.4+, self-closing XHTML tags are ignored; these do not have to be included in the allowable_tags list. |
strip_tags(string, allowable_tags [optional parameter]) ;
[Since |
strip_tags() : returns the stripped string. |
stripcslashes()
[Unquote string quoted with addcslashes()] |
This function returns a string with backslashes stripped off. Recognizes C-like \n, \r…, octal and hexadecimal representation.] | stripcslashes(string) ; |
stripcslashes() : returns the unescaped string. |
stripos()
[Find the position of the first occurrence of a case-insensitive substring in a string] |
This function finds the numeric position of the first case-insensitive occurrence of needle in the haystack string. | stripos(haystack, needle, offset [optional parameter with a default value of 0]) ;
[needle may be a string of one or more characters; if it is not a string, it is converted to an integer and applied as the ordinal value of a character. If offset is specified and positive, searching will begin this number of characters counted from the beginning of haystack; if negative, searching will begin this number of characters counted from the end of haystack.] |
stripos() : returns the position of where the case-insensitive needle exists relative to haystack [independent of offset]. String positions start at 0 and not 1. Returns FALSE if needle was not found. |
stripslashes()
[Un-quotes a quoted string] |
This function un-quotes a quoted string. If magic_quotes_sybase is on, no backslashes are stripped off but two apostrophes are replaced by one instead. |
stripslashes(string) ; |
stripslashes() : returns a string with backslashes stripped off. Double backslashes are made into a single backslash. |
stristr()
[Case-insensitive |
This function returns all of haystack string starting from and including the first occurrence of case-insensitive needle string to the end. | stristr(haystack, needle, before_needle [optional parameter with a default version of FALSE]) ;
[if needle is not a string it is converted to an integer and applied as the ordinal value of a character. If before_needle is TRUE, |
stristr() : returns the matched substring, or FALSE if needle is not found. |
strlen()
[Get string length] |
This function returns the length of the given string. | strlen(string) ; |
strlen() : returns the length of string in bytes [rather than characters], or 0 if string is empty. Returns NULL and emits an E_WARNING-level error when used on an array. PHP versions prior to 5.3 treated arrays as the word ‘Array’, thus returning a string length of 5 and generating an E_NOTICE-level error. |
strnatcasecmp()
[Case insensitive string comparisons using a “natural order” algorithm] |
This function implements a case-insensitive ‘natural order’ comparison algorithm that orders alphanumeric strings in the same manner that a human being would. | strnatcasecmp(string_1, string_2) ; |
strnatcasecmp() : returns <0 if string_1 is less than string_2; 0 if string_1 is equal to string_2; and >0 if string_1 is greater than string_2. |
strnatcmp()
[Case sensitive string comparisons using a “natural order” algorithm] |
This function implements a case-sensitive ‘natural order’ comparison algorithm that orders alphanumeric strings in the same manner that a human being would. | strnatcmp(string_1, string_2) ; |
strnatcmp() : returns <0 if string_1 is less than string_2; 0 if string_1 is equal to string_2; and >0 if string_1 is greater than string_2. |
strncasecmp()
[Binary safe case-insensitive string comparison of the first n characters] |
This function – similar to strcasecmp() – performs a binary-safe case-insensitive string comparison of the first n characters [specified by length] in string_1 and string_2. |
strncasecmp(string_1, string_2, length) ; |
strncasecmp() : returns <0 if string_1 is less than string_2; 0 if string_1 is equal to string_2; and >0 if string_1 is greater than string_2. |
strncmp()
[Binary safe string comparison of the first n characters] |
This function – similar to strcmp() – performs a binary-safe case-sensitive string comparison of the first n characters [specified by length] in string_1 and string_2. |
strncmp(string_1, string_2, length) ; |
strncmp() : returns <0 if string_1 is less than string_2; 0 if string_1 is equal to string_2; and >0 if string_1 is greater than string_2. |
strpbrk()
[Search a string for any of a set of characters] |
This function searches the case-sensitive haystack string for a charlist [‘p’attern]. When a character is found, a string is returned representing the segment of haystack broken from the case-sensitive charlist match to the end of the string. | strpbrk(haystack, charlist) ; |
strpbrk() : returns a string starting from the character found, or FALSE if charlist is not found. |
strpos()
[Find the position of the first occurrence of a substring in a string] |
This function finds the numeric position of the first occurrence of needle in the haystack string. strpos() may return FALSE but may also return a non-Boolean value which evaluates to FALSE. The use of the === operator is recommended for testing the return value of this function. |
strpos(haystack, needle, offset [optional parameter, with a default value of 0]);
[If offset is specified and positive, search will start this number of characters from the start of haystack. If offset is specified and negative, search will begin this number of characters from the end of haystack.] |
strpos() : returns the position of where needle exists relative to the start of the haystack string [independent of offset]. Returns FALSE if the needle was not found. |
strrchr()
[Find the last occurrence of a character in a string] |
This function returns the portion of the haystack string which starts at the last [‘reverse’] occurrence of the needle character and continues till the end of haystack. | strrchr(haystack, needle);
[If needle comprises more than one character, only the first one is used; this behaviour differs from |
strrchr() : returns the portion of string, or FALSE if needle is not found. |
strrev()
[Reverse a string] |
This function returns string, reversed. | strrev(string); |
strrev() : returns the reversed string. |
strripos()
[Find the position of the last occurrence of a case-insensitive substring in a string] |
This function finds the numeric position of the last [‘reverse’] case-insensitive occurrence of needle in the haystack string. | strripos(haystack, needle, offset [optional parameter with a default value of 0]) ;
[needle may be a string of one or more characters; if it is not a string, it is converted to an integer and applied as the ordinal value of a character. If offset is specified and positive, searching will begin this number of characters counted from the beginning of haystack; if negative, searching will begin this number of characters counted from the end of haystack.] |
strripos() : returns the position of where the last [‘reverse’] case-insensitive needle exists relative to haystack [independent of offset]. String positions start at 0 and not 1. Returns FALSE if needle was not found. |
strrpos()
[Find the position of the last occurrence of a case-sensitive substring in a string] |
This function finds the numeric position of the last [‘reverse’] case-sensitive occurrence of needle in the haystack string. | strrpos(haystack, needle, offset [optional parameter with a default value of 0]) ;
[needle may be a string of one or more characters; if it is not a string, it is converted to an integer and applied as the ordinal value of a character. If offset is specified and positive, searching will begin this number of characters counted from the beginning of haystack; if negative, searching will begin this number of characters counted from the end of haystack.] |
strrpos() : returns the position of where the last [‘reverse’] case-sensitive needle exists relative to haystack [independent of offset]. String positions start at 0 and not 1. Returns FALSE if needle was not found. |
strspn()
[Finds the length of the initial segment of a string consisting entirely of characters contained within a given mask] |
This function finds the length [‘span’] of the initial segment of subject string consisting entirely of characters contained within a given mask. If start and length are omitted, then all of subject will be examined. If start and length are included, then the effect will be the same as calling strspn(substr($subject, $start, $length), $mask) . |
strspn(subject, mask, start [optional parameter], length [optional parameter]);
[If start is specified and is positive, |
strspn() : returns the length [‘span’] of the initial segment of subject string which consists entirely of characters in mask. When a start parameter is set, length is counted from this starting position – not from the beginning of subject. |
strtok()
[Tokenize string] |
This function splits string into smaller strings [tokens], with each of these smaller strings being delimited by any character from token. Only the first call to strtok() uses the string argument; each subsequent call only needs the token to use, since it keeps track of where it is in the current string. To start again – or to tokenize a new string – simply call strtok() with the string argument again to initialize it. Multiple tokens are permitted in the token parameter; the string will be tokenized when any one of the characters in the argument is found. |
First function call:strtok(string, token); Subsequent function calls: strtok(token); |
strtok() : returns a string token. |
strtolower()
[Make a string lowercase] |
This function returns string with all alphabetic characters converted to lowercase. ‘Alphabetic’ is determined by the current locale: in the default C locale, characters such as umlaut-A – for example – will not be converted. | strtolower(string); |
strtolower() : returns string converted to lowercase. |
strtoupper()
[Make a string uppercase] |
This function returns string with all alphabetic characters converted to uppercase. ‘Alphabetic’ is determined by the current locale: in the default C locale, characters such as umlaut-A – for example – will not be converted. | strtoupper(string); |
strtoupper() : returns string converted to uppercase. |
strtr()
[Translate characters or replace substrings] |
If passed three arguments, this function returns a copy of string where all occurrences of each [single-byte] character in from have been translated to the corresponding character in to, videlicet– every occurrence of $from[$n] has been replaced with $to[$n] , where n is a valid offset in both arguments. If from and to have different lengths, the extra characters in the longer of the two will be ignored; the length of string will be the same as the return value’s. |
With three arguments:strtr(string, from, to); With two arguments: strtr(string, replace_array);
[If given two arguments, the replace_array should be of the form |
strtr() : returns the translated string on success. If replace_array contains a key which is an empty string, FALSE is returned. If string is not scalar it is not typecasted into a string; instead a warning is raised and NULL is returned. |
substr_compare()
[Binary safe comparison of two strings from an offset, up to length characters] |
This function compares main_string – from position offset – with second_string [‘substring’] [up to length characters]. | substr_compare(main_string, second_string, offset, length [optional parameter, with a default value equal to the largest of *length of second_string*/*main_string – offset], case_insensitivity [optional parameter with a default value of FALSE]);
[offset specifies the position at which to start counting. If negative, the comparison begins at offset characters from the end of the string.] |
substr_compare() : returns <0 if main_string from position offset is less than second_string; returns >0 if main_string from position offset is greater than second_string; returns 0 if main_string from position offset is equal to second_string. A WARNING is printed and FALSE is returned if offset is equal to or greater than the length of main_string, or the length is set and less than 1 in PHP versions prior to 5.5.11. |
substr_count()
[Count the number of substring occurrences] |
This function returns the number [‘count’] of times the needle substring occurs in the haystack string. needle is case-sensitive. | substr_count(haystack, needle, offset [optional parameter with a default value of 0], length [optional parameter]);
[offset specifies the position at which to start counting. If negative, the comparison begins at offset characters from the end of the string. length specifies the maximum length after offset to search for the needle. A WARNING is output if offset plus length is greater than the haystack length. A negative length counts from the end of haystack.] |
substr_count() : returns an integer representation of the number of occurrences of needle within haystack. |
substr_replace()
[Replace text within a portion of a string] |
This function replaces a copy of string delimited by the start and optional length parameters [thus, a ‘substring’] with the replacement string. | substr_replace(string, replacement, start, length [optional parameter, with a default value of strlen(string) ]);
[string represents the input string. An array of strings can be provided; in this case, the replacements will occur on each string in turn. replacement, start, and length may be provided as either scalar values or as arrays (whereby the corresponding array element will be used for each input string). |
substr_replace() : the result string is returned. If string is an array, then an array is returned. |
substr()
[Return part of a string] |
This function returns the portion [‘substring’] of string specified by the start and length parameters. | substr(string, start, length [optional parameter]);
[string represents the input string; must be one character or longer. |
substr() : returns the extracted part of string [the ‘substring’]; FALSE on failure, or an empty string. |
trim()
[Strip whitespace (or other characters) from the beginning and end of a string] |
This function returns a string with whitespace stripped [‘trimmed’] from the beginning and end of string. If character_mask is unspecified, trim() will strip the following characters: an ordinary space; a tab; a new line; a carriage return; the NUL-byte; and the vertical tab. |
trim(string, character_mask [optional parameter, with a default value of “\t\n\r\0\x0B”]);
[Further characters can be specified in the character_mask parameter. With .., a range of characters can be specified.] |
trim() : returns the trimmed string. |
ucfirst()
[Make a string’s first character uppercase] |
This function returns a string with the first character of string capitalized [‘uppercased’], if that character is alphabetic. ‘Alphabetic’ is determined by the current locale; in the default C locale, characters such as umlaut-a will not be capitalized. | ucfirst(string); |
ucfirst() : returns the resulting string, after its first character has been uppercased if it is suitably ‘alphabetic’. |
ucwords()
[Uppercase the first character of each word in a string] |
This function returns a string with the first character of each word in string capitalized [‘uppercased’], if that character is ‘alphabetic’. A ‘word’ is defined as any string of characters that is immediately after any character listed in the delimiters parameter. | ucwords(string, delimiters [optional parameter, with a default value of " \t\r\n\f\v" ]);
[The optional delimiters parameter contains the word separator characters. By default these are: space; horizontal tab; carriage return; form-feed; newline; and vertical tab.] |
ucwords() : returns the modified string, after the first character of all words have been uppercased if suitably ‘alphabetic’. |
vfprintf()
[Write a formatted string to a stream] |
This function writes [‘prints’] a string produced according to format to the stream resource specified by handle. Operates as fprintf() but accepts an array of args, rather than a variable number of arguments. |
vfprintf(handle, format, args);
[See |
vfprintf() : returns the length of the outputted string. |
vprintf()
[Output a formatted string] |
This function displays [‘prints’] array values as a string formatted according to format. Operates as printf() but accepts an array of arguments, rather than a variable number of arguments. |
vprintf(format, args);
[See |
vprintf() : returns the length of the outputted string. |
vsprintf()
[Return a formatted string] |
vsprintf() operates as sprintf() but accepts an array of arguments, rather than a variable number of arguments. |
vsprintf(format, args);
[See |
vsprintf() : returns the array values as a string formatted according to format. |
wordwrap()
[Wraps a string to a given number of characters] |
This function wraps a string [‘word’] to a given number of characters using a string break character. | wordwrap(string, width [optional parameter, default value = 75], break [optional parameter, default value = "\n" ], cut [optional parameter, default value = FALSE]);
[If cut is set to TRUE, the string is always wrapped at or before width. When FALSE, the function does not split the word even if it is wider than width.] |
wordwrap() : returns the given string [‘word’] wrapped at the specified length. |
FILL IN FORM AND CLICK SUBMIT TO ADD YOUR STATISTICS TO THE LEADERBOARD:
Forty-year-old father of three wonderful children [William, Seth, and Alyssa]. Works as an Assistant Technical Officer in the Sterile Services Department of Treliske Hospital, Cornwall. Enjoys jogging, web design, learning programming languages, and supporting Arsenal FC. Obtained a BA degree in English from the University of Bolton in 2008, and has continued to gain qualifications in a diverse range of subjects thereafter.