Charles C. Spencer
CIS 52N Spring 2008
Practice Chapter 5

Constructing Text Strings:

"Dr. Livingstone, I presume?"

strlen:

Returns the number of characters in a string.

The book title contains 23 characters.

strpos:

Performs a case-sensitive search and returns the position of the last occurrence of one string in another string.

$Email = "president@whitehouse.gov"; searching for: '@' and 'p', or if '@' exits...

9
0

The email address contains an @ character.

strchr:

Performs a case-sensitive search for specified characters in a string and returns a substring from the last occurrence of the specified characters to the end of the string.

The domain identifier of the email address is .gov.

substr:

Returns a portion of a string.

The name portion of the email addres is 'president'.


The domain name portion of the email address is 'whitehouse'.

str_replace(), str_ireplace(), and substr_replace:

str_ireplace: performs a case-insensitive replacement of all occurances of specified characters in a string.
str_replace: performs a case-sensitive replacement of all occurrences of speccified characters in a string.
substr_replace: replaces characters within a specified portion of a string.

'str_replace' : replace with new email address.

vice.president@whitehouse.gov


'substr_replace'

vice.president@whitehouse.gov


strpos, substr_replace:

George Herbert Walker h was the 41st president of the United States.

George Walker Bush is the 43rd president of the United States.

strtok:

breaks a string into smaller strings, called 'tokens'.

Geroge W. Bush
William Clinton
George H.W. Bush
Ronald Regan
Jimmy Carter
explode/implode:

The 'explode()' function splits a string into an indexed array at a specified separator.

George W. Bush
William Clinton
George H.W. Bush
Ronald Reagan
Jimmy Carter

The 'implode()' function combines an array's elements into a single string, separated by specified characters.

George W. Bush, William Clinton, George H.W. Bush, Ronald Reagan, Jimmy Carter
strcasecmp() and strcmp():

strcasecmp() performs a case-insensitive comparison of two strings.

strcasecmp("Don", "don"); // returns 0;

;

strncmp() performs a case-sensitive comparison of strings.

strcmp("Dan", "Don"); // returns -1
strcmp("Don", "Dan"); // returns 1
strcmp("Don", "Don"): // returns 0
strcmp("Don", "don"); // returns -1

strncmp:
$FirstCity = "San Diego"; $SecondCity = "San Jose";

Both cities begin with 'San'.

similar_text() and levenshtein():

similar_text and levenshtein() functions are used to determine the similarity between two strings.

The names "Don" and "Dan" have 2 characters in common.

You must change 1 character(s) to make the names "Don" and "Dan" the same.

soundex() and metaphone():

soundex() and metaphone() functions determine whether two strings are pronounced similarly.

$FirstName="Gosselin"; $SecondName="Gauselin";

metaphone(): (returns a code representing an English word's approximate sound)

The names are pronounced the same.

soundex(): returns a value representing a name's phonetic equivalent.

The names are pronounced the same.

isset(), empty(), and is_numeric:

isset() function determines whether a variable has been declared and initialized.
empty() function determines whether the variable is empty.
is_numeric() function tests whether a variable contains a numeric string.

BodyMassIndex:

Specifying Types: value = 123.123

Binary integer: 1111011
ASCII character: {
Decimal integer: 123
Decimal integer: 123.12
Unsigned decimal integer: 123
Floating-point number: 123.123000
Octal integer: 173
String: 123.123
Lowercase hexadecimal integer: 7b
Uppercase hexadecimal integer: 7B

Home Page
Lab 2 Exercises