PHP - Chapter 3 - Manipulating Strings

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

soundex(); and metaphone();

2 Function that is used to determine if 2 strings are pronounced similarly.

similar_text(); and levenshtein();

2 Function that is used to determine similarity of 2 strings.

false, escape character

An escape sequence is is the combination of a release character combined with one or more other characters.

Subexpressions

Characters contained in the parentheses within a regular expression.

parsing

Dividing a string into substrings

Simple String Syntax

Enclosing string and variable in double quotes.

Complex String Syntax

Enclosing variable in curly braces inside double quotes. Example of creating pluralization of a variable. $Vegetable = "carrot"; echo "<p>Do you have any {$Vegetable}s?</p>";

str_tok();

Function that breaks strings into smaller strings called tokens.

implode();

Function that combines an array's elements into a single string, separated by specified character like a comma.

strtolower();

Function that converts a string to all lowercase.

strtoupper();

Function that converts a string to all uppercase.

ucwords();

Function that converts all of the words of a string to uppercase.

lcfirst();

Function that converts the first letter of a string to lowercase.

ucfirst();

Function that converts the first letter of a string to uppercase.

strlen();

Function that counts characters in a string

str_word_count();

Function that counts words in a string.

str_ireplace();

Function that performs a case insensitive replacement of a substring in a string. Arguments are the search substring, the replacement substring, and the string to search.

strcmp();

Function that performs a case sensitive comparison.

str_replace();

Function that performs a case sensitive replacement of a substring in a string. Arguments are the search substring, the replacement substring, and the string to search.

strpos();

Function that performs a case sensitive search for a string and returns the starting position of the 1st occurrence. Arguments are the string and the substring looking for. Can also be used to determine the existence of a string and is evaluated for true/false.

strcasecmp();

Function that performs a case-insensitive comparison.

substr_replace();

Function that performs a positional replacement of a substring in a string. Arguments are the string to search, replacement substring, the start position, and the length.

soundex();

Function that returns a code representing the phonetic equivalent of a string. Thackston returns T235

substr();

Function that returns a portion of a string. Parameters are the string name, beginning position, length.

metaphone();

Function that returns a value representing the approximate sound of a string. Thackston returns okstn;

similar_text();

Function that returns the number of characters in common

levenshtein();

Function that returns the number of characters to change for the strings to match

strrev();

Function that reverses the order of the characters in a string.

strchr();

Function that searches a string from the beginning and returns the last portion of the string starting with the substring searching for.

strrchr():

Function that searches a string from the end and returns the last portion of the string starting with the substring searching for.

str_split(); or explode();

Function that splits a string into an indexed array where each character in the string becomes an entity in the array.

strshuffle();

Function that that randomly scrambles characters of a string.

trim();

Function that trims off the leading and trailing spaces.

ltrim();

Function that trims off the leading spaces.

rtrim();

Function that trims off the trailing spaces.

b) a delimiter

In the following code, what is the role of the ';' character? $PresidentArray = explode (";", $Presidents); a) a check b) a delimiter c) a control d) a regulator

pipe character: |

Metacharacter that allows a string to be composed of an alternate set of substrings.

Regular Expression

Patter of specially formatted strings that can be used to validate the structure of a string.

Character Class

Set of multiple characters enclosed in square brackets [ ] that are treated as a single unit.

metacharacters

Special Characters in a Regular expression that define pattern matching rules

False, the ? indicates the preceding values are optional

The ? in the following regular expression indicates the preceding values are required "/^\d{5}(-\d{4})?$/"

Birth Date: MM/DD/YYYY or MM/DD/YY

The regular expression ^([\d]|1[0,1,2])/([0-9]|[0,1,2][0-9]|3[0,1])/(\d{2}|\d{4})$ is used to validate which of the following patterns:

True

True or False, If you include an array within a text string, you need to use complex string syntax.

True

True or False, PHP converts the boolean values TRUE and FALSE to 1 and 0, respectively.

False, a string is returned

True or False, The data type returned from the implode() function is an array.

True

True or False, The following regular expression is a valid pattern for evaluating zip-codes in the U.S. /"^\d{5}(-\d{4})?$"/

False, the escape character

True or False, The release character tells the computer or interpreter that the character that follows it has a special purpose.

True

True or False, The type of structure in which variables are placed within curly braces inside a string is called complex string syntax.

backslash character

What character is used to match metacharacters as literal values.

b) \'

What is the escape sequence for a single quotation mark? a) There is no escape sequence for a single quotation mark b) \' c) /' d) \\'

c) Hello Queen of Hearts

What is the output of the following code: $names = array ("Alice", "Cheshire", "Hatter", "Queen of Hearts", "White Rabbit"); $index = 3; echo "Hello {$names[$index]}" a) Hello {names[3]} b) Hello Hatter c) Hello Queen of Hearts d) Hello {names[$index]}

b) king

What is the output of the following code? $ExampleString = "woodworking project"; echo substr($ExampleString,-12,4) . "<br />\n"; a) wood b) king c) project d) work

d) str_replace ( $search , $replace , $subject )

What is the proper syntax for the str_replace() function (note: $search is text string you are looking for, $replace is the value you want to replace the $search text with, $subject is the text string you are searching within) a) str_replace ( $subject, $replace, $search ) b) str_replace ( $replace, $search , $subject ) c) str_replace ( $subject, $search , $replace ) d) str_replace ( $search , $replace , $subject )

b) { }

Which of the following character sets do you use for complex string syntax? a) // // b) { } c) ( ) d) [ ]

d) echo '<p>Welcome to the 'combat zone'!</p>';

Which of the following echo statements is invalid? a) echo "<p>Welcome to the combat zone!</p>"; b) echo '<p>Welcome to the "combat zone"!</p>'; c) echo "<p>Welcome to the 'combat zone'!</p>"; d) echo '<p>Welcome to the 'combat zone'!</p>';

d) strlen()

Which of the following functions returns the length of a string? a) substr_count() b) strspan() c) str_count() d) strlen()

b and c

Which of the following operators can be used with strings? (choose all that apply) a) == b) . c) .= d) +=

False

\. Is used to match any single character in a pattern

c) Parsing

_________________________ refers to the act of extracting characters or substrings from the larger string. a) Delimiting b) Separating c) Parsing d) Extracting

Quantifiers

type of metacharacter that specify the number of times a particular match may occur.

Concatenation assignment operator

using a period and a equal sign to combine values

Concatenation Operator

using a period to combine values

Escape Characters

using the slash in order to tell php that the following character has a purpose. Examples \\, \", \', \n


Kaugnay na mga set ng pag-aaral

CED 300 Aging and the Services for Older Adults

View Set

Chapter 5 Review (Questions 1-6,14-23,26,28,29,35-37) (due Oct 9, typed)

View Set

ACCT 2100 (W01) - Exam Questions

View Set

Worksheet 18.3: Piercing the Corporate Veil & Corporate Directors and Officers

View Set

The Native American Voice: Mastery Test

View Set