Sie sind auf Seite 1von 6

Practice 5

My Functions
<?php
//My Functions
//welcome Greeting
function welcome_greeting($name)
{
echo "Welcome to our website $name!";
}
//operations
function multiplication($number1,$number2)
{
$result=$number1*$number2;
echo "You have selected multiplication as an operation the sum of $number1 and $number2 is $result.";
}
function division($number1,$number2)
{
$result=$number1/$number2;
echo "You have selected multiplication as an operation the sum of $number1 and $number2 is $result.";
}
function addition($number1,$number2)
{
$result=$number1+$number;
echo "You have selected multiplication as an operation the sum of $number1 and $number2 is $result.";
}
function subtraction($number1,$number2)
{
$result=$number1-$number;
echo "You have selected multiplication as an operation the sum of $number1 and $number2 is $result.";
}

?>

Problem1

html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="problem1.php">
<p>
<label for="name">Enter Name</label>
<input type="text" name="name" id="name" />
</p>
<p>
<input type="submit" name="button" id="button" value="Submit" />
</p>
</form>
</body>
</html>

php
<?php
include 'myfunctions.php';
$name=$_POST['name'];
welcome_greeting($name);

?>

Problem2

html
<form name="form1" method="post" action="problem2.php">
<p>
<label for="number1">Number 1</label>
<input type="text" name="number1" id="number1">
</p>
<p>
<label for="number2">Number 2</label>
<input type="text" name="number2" id="number2">
</p>
<p>
<label for="operations">Operation </label>
<select name="operation" id="operations">
<option>multiplication</option>
<option>subtraction</option>
<option>addition</option>
<option>division</option>
</select>
</p>
<p>
<input type="submit" name="button" id="button" value="Submit">
</p>
</form>

php
<?php
include 'myfunctions.php';
$operation=$_POST['operation'];
$number1=$_POST['number1'];
$number2=$_POST['number2'];

if($operation="multiplication")
{
echo multiplication($number1,$number2);
}
elseif($operation="division")
{
echo division($number1,$number2);
}
elseif($operation="addition")
{
echo addition($number1,$number2);
}
elseif($operation="subtraction")
{
echo subtraction($number1,$number2);
}

Problem3
*could not connect to server
html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="problem3.php">
<p>
<label for="number1">Number 1</label>
<input type="text" name="number1" id="number1" />
</p>
<p>
<label for="number2">Number 2</label>
<input type="text" name="number2" id="number2" />
</p>
<p>
<label for="number3">Number 3</label>
<input type="text" name="number3" id="number3" />
</p>
<p>
<label for="number4">Number 4</label>
<input type="text" name="number4" id="number4" />
</p>
<p>
<label for="number5">Number 5</label>
<input type="text" name="number5" id="number5" />
</p>
<p>
<label for="number6">Number 6</label>
<input type="text" name="number6" id="number6" />
</p>
<p>
<label for="number7">Number 7</label>
<input type="text" name="number7" id="number7" />
</p>
<p>
<label for="number8">Number 8</label>
<input type="text" name="number8" id="number8" />
</p>
<p>
<label for="number9">Number 9</label>
<input type="text" name="number9" id="number9" />
</p>
<p>
<label for="number10">Number 10</label>
<input type="text" name="number10" id="number10" />

</p>
<p>
<input type="submit" name="submitt" id="submitt" value="Submit" />
</p>
</form>
</body>
</html>

php
Problem4
A recursion happens when a function calls on itself, this process will happen over and over again until the recursion
meets some kind of end condition or what we call base case. The part of the function that calls itself is called the
recursive case. When the base case is met the function does any finishing operation if needed then exits and runs
the rest of the code.
function factorial($number)
//This means that we are doing this defined operation
{
if($number<2)
//if our current number is less than 2, the code will return 1 or continue on to else...Also once this part has been
completed the code no longer calls itself and the rest of the code is run outside the function.
{
return 1;
}
}
else
{
return($number*factorial($number-1));
//when the first if statement is not true then do operation as defined which does the number times the number minus
1. The factorial is the part that calls the code and runs the recursion again.
}
}
echo factorial(6);
//This prints the value that comes after the recursion has looped six times.
//Once the first

Problem5
*could not connect to server
html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Search.html</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="search.php">
<p>
<label for="text">Text Here</label>
<input type="text" name="text" id="text" />
</p>
<p>
<label for="searchterm">Search Term</label>
<input type="text" name="searchterm" id="searchterm" />
</p>
<p>
<input type="submit" name="sumbit" id="sumbit" value="Submit" />
<label for="text2"></label>
</p>
</form>
</body>
</html>

php
<?php
$text=$_POST['text'];
$serach=$_POST['searchterm'];
$length=strlen($text);
if(strstr($text,$search)==false)
{echo "Sorry, your search was unsuccessful";}
else
{
for($pos=0;$pos<=$length;$pos++)
{if($pos==(strpos($text,$search,$pos)))
{echo "The search term $search was found at position $pos </br>";}
}}

?>

Das könnte Ihnen auch gefallen