Site icon sharedsapience.info

PHP String Function Mini-Quiz 6: From str_shuffle() to stripcslashes().

The str_shuffle PHP String function, sized for tablet viewing.

An image of the str_shuffle() PHP String function, sized for tablet 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
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, strcspan() will begin examining subject at the position specified by start. length represents the length of the segment of subject to search. If length is given and is non-negative, subject will be examined for length characters after the start position. If length is given and is negative, subject will be examined from start position up to length characters from the end of the string. If start and length are included, this function has the same effect as calling strcspn(substr(subject, start, length), mask).]

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() does not validate the HTML, partial or broken tags can result in the removal of more data than was expected. This function does not modify any attributes on the tags that you allow using allowable_tags. Tag names within the input HTML that are longer than 1023 bytes will be treated as invalid, regardless of the allowable_tags parameter.]

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.

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


Exit mobile version