Site icon sharedsapience.info

PHP String Function Mini-Quiz 7: From stripos() to strpos().

The PHP String function, sized for mobile viewing.

An image of the stripos() PHP String function, sized for mobile 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
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 strstr()]

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 part of haystack up to – but excluding – the first occurrence of needle.]

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.

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


Exit mobile version