Categories
php unit

Unit 7 Functions

This is just useful notes for my own later use. Spoiler alert if you don’t want the answers to these lessons than don’t read on any farther.

Lesson 7:

1.) Introducing Functions

strlen() string function. You pass this a string or a varialbe containing a string and it will return the number of characters in the string. Example:

$length = strlen("Samuel");
print $length;

2.) String Functions

substr() You pass this function the string you want to get a subsctring of, the character in your string to start at, and how many characters you want after your starting point. For example:

print the first 3 letters of my name:

$myname = "Samuel Bell";
$partial = substr($myname,0,3);
print $partial;

print my name in uppercase:

$uppercase = strtoupper($myname);
print $uppercase;

print my name in lowercase:

$lowercase = strtolower($uppercase);
print $lowercase;