You have one Question, Which have four parts,
1st... PHP scriptIn a HTML document, use PHP to obtain the following :The user will write a sentence as a value of a predefined variable.The output should look like this :The sentence you entered is :This is my sentenceIt is composed of :• 4 different words• 19 characters (including spaces)Note : Your program should make sure the final output is in lower case with the first letter in upper case.
2nd... PHP script
In a HTML document, use PHP to obtain the following :
The user will enter different values for the main global variables
(table
diameter and side a and be of a triangle) and the program will
output a
message such as the following:
Date :
Saturday, April 6th 2019
Time :
10:25 am
Your table details :
Diameter: User enters diameter
Circumference : Program output
Surface area : Program output
The length of your triangle hypotenuse :
Side a : User enters length of side a
Side b : User enters length of side b
Hypotenuse : Program output
3rd.... Guessing the secret number
In a HTML document, use PHP to obtain the following :
The first variable ($number) to be declared is the one representing
the
number chosen by the user.
The second variable declared ($secret) is the secret number. You
need for
the program to generate a random number between 0 and 10.
You need messages saying whether the secret number is higher, lower
or
equal to the chosen number.
4th... Create a visits counter
In a HTML document, use PHP to show the number of time the page
has
been visited like in the following example :
«This page has received 6 visits up to now. »
You will need to create a text file which will be used as a counter
and
you will need to read and write in this text file each time the
page is visited.
Here is the code :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test</title>
<style>
.container{
width: 80%;
margin: 0 auto;
padding: 50px 50px;
}
.form-control{
margin: 15px;
display: flex;
flex-direction: column;
}
.m-15{
margin: 15px;
}
</style>
</head>
<body>
<div class="container">
<h2>Question 1</h2>
<form method="GET">
<div class="form-control">
<label>Enter String</label>
<input type="text" name="string">
</div>
<div class="m-15">
<button type="submit" class="btn" name="string-btn">Submit</button>
</div>
</form>
<div class="m-15">
<h3>
<?php
if(isset($_GET["string-btn"])){
$words=str_word_count($_GET["string"]);
$chars=strlen($_GET["string"]);
echo "The sentence you entered is : ".$_GET["string"]." It is composed of : ".$words." words ".$chars." characters.(Including spaces)";
}
?>
</h3>
</div>
<h2>Question 2</h2>
<form method="GET">
<div class="form-control">
<label>Diameter</label>
<input type="number" name="dia">
</div>
<div class="form-control">
<label>Enter 2 sides of triangle</label>
<input type="number" name="sideA">
<input type="number" name="sideB">
</div>
<div class="m-15">
<button class="btn" name="math-btn" type="submit">Submit</button>
</div>
</form>
<div class="m-15">
<?php
if(isset($_GET["math-btn"])){
echo "<h3>"."Date :"."</h3>";
$month_num =date("m");
$month_name = date("F", mktime(0, 0, 0, $month_num, 10));
echo "<h3>".date('l').", ".$month_name." ".date("d")."th ".date("Y")."</h3>";
echo "<h3>".date('h:i A', strtotime(time()))."</h3>";
echo "<h3>"."Diameter: ".$_GET["dia"]."</h3>";
echo "<h3>"."Circumference: ".($_GET["dia"]*pi())."</h3>";
$sa=($_GET["dia"]/2)*($_GET["dia"]/2)*pi();
echo "<h3>"."Surface Area: ".$sa."</h3>";
echo "<h3>"."The length of your triangle hypotenuse :"."</h3>";
echo "<h3>"."Side a :".$_GET["sideA"]."</h3>";
echo "<h3>"."Side b :".$_GET["sideB"]."</h3>";
$hp=sqrt(($_GET["sideA"]*$_GET["sideA"])+($_GET["sideB"]*$_GET["sideB"]));
echo "<h3>"."Hypotenuse : ".$hp."</h3>";
}
?>
</div>
<h2>Question 3</h2>
<form method="GET">
<div class="form-control">
<label>Number</label>
<input type="number" placeholder="0-10" maxlength="10" name="s-number">
</div>
<div class="m-15">
<button type="submit" class="btn" name="secret-btn">Submit</button>
</div>
</form>
<div class="m-15">
<h3>
<?php
if(isset($_GET["secret-btn"])){
$number=$_GET["s-number"];
$secret=rand(0,10);
if($number<$secret){
echo "The number is smaller than the secret number";
}
else if($number>$secret){
echo "The number is bigger than the secret number";
}
else{
echo "The number is equal to the secret number";
}
}
?>
</h3>
</div>
<h2>Question 4</h2>
<div class="m-15">
<h3>
<?php
session_start();
$counterfile = fopen("counter.txt", "r") or die("Unable to open file!");
$counter=0;
if(filesize("counter.txt")!=0){
$counter=number_format(fread($counterfile,filesize("counter.txt")));
}
if(isset($_SESSION['views'])){
$counter=$counter+1;
}
echo"This page has recieved ".$counter." visits upto now";
fclose($counterfile);
$counterfile = fopen("counter.txt", "w") or die("Unable to open file!");
fwrite($counterfile,$counter);
fclose($counterfile);
?>
</h3>
</div>
</div>
</body>
</html>
Create a counter.txt file in the same folder
Get Answers For Free
Most questions answered within 1 hours.