Site icon sharedsapience.info

PHP String Function Mini-Quiz 1: From addcslashes() to crc32().

The first two rows of the PHP String Mini-Quiz 1, sized for desktop viewing.

An image of the first two rows of the PHP String Mini-Quiz 1, sized for desktop viewing.

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:

An example of the layout designed for mobile phones
An example of the layout designed for tablets
An example of the layout designed for desktop computers

PURPOSE:

This webpage serves two purposes:

  1. It provides a reference table for the PHP string functions, with information extracted and condensed from w3schools.com and php.net.
  2. 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 magic_quotes_gpc was on by default and it effectively ran addslashes() on all GET, POST, and COOKIE data. Using addslashes() on this data will result in double escaping, and should be avoided. get_magic_quotes_gpc() can be used to check if magic_quotes_gpc is on.]

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 will strip the following characters: an ordinary space; a new line; a tab; a carriage return; the NUL byte; and a vertical tab.]

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.

Web design certified by:
Click images for proof of certification.


Exit mobile version