PHP Week 3

//takes input string and convert to lower and upper case respectively
echo "Insert input: ";
$string_lower = strtolower($string_user);
$string_upper = strtoupper($string_user);
echo "\nLowercase: $string_lower \nUppercase: $string_upper\n";

Fany-Savinas-Mac:PHP Fany$ php lower_upper_case.php
Insert input: I Am Awesome!

Lowercase: i am awesome!

Uppercase: I AM AWESOME!


//adds, substracts, multiplies, divides two input numbers on different lines
echo "Insert Initial Number: ";
echo "Insert Final Number: ";
$sum_total_one = $number1 + $number2;
$sum_total_two = $number1 - $number2;
$sum_total_three = $number1 * $number2;
$sum_total_four = $number1 / $number2;
echo "\n$number1 + $number2= $sum_total_one\n";
echo "$number1 - $number2= $sum_total_two\n";
echo "$number1 x $number2= $sum_total_three\n";
echo "$number1 / $number2= $sum_total_four\n\n";

Fany-Savinas-Mac:PHP Fany$ php number_maths.php
Insert Initial Number: 3
Insert Final Number: 5

3 + 5= 8
3 - 5= -2
3 x 5= 15
3 / 5= 0.6


//echoes initial and final with an 'and'
echo "Insert Initial Input: ";
//trim() removes whitespaces added when inserting variable
echo "Insert Final Input: ";
echo "\n$initial_noun and $final_noun\n";

Fany-Savinas-Mac:PHP Fany$ php two_noun.php
Insert Initial Input: Dog
Insert Final Input: Cat

Dog and Cat


//repeats input a specified number of times
echo "Insert Initial Input: ";
echo "Insert Repetition: ";
echo "\n";
echo str_repeat("$string\n",$repeat);
echo "\n";

Fany-Savinas-Mac:PHP Fany$ php repeat_input.php
Insert Initial Input: Epic
Insert Repetition: 3


This entry was posted in Computing and tagged . Bookmark the permalink.

Leave a reply