Question

You have one Question, Which have four parts, 1st... PHP scriptIn a HTML document, use PHP...

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.

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
This will be my third time submitting this question. THERE SHOULD BE NO USE OF CSS...
This will be my third time submitting this question. THERE SHOULD BE NO USE OF CSS OR SWITCH STATEMENTS IN THE JAVASCRIPT. Even though there is stylesheet in the HTML file do no create a new one. Project Standards: Students will use click events to capture user input. Students will use variables to store information needed by their application and keep track of their program’s state. Students will use conditionals to control project flow. Project Task You will be building...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
After reading the following article, how would you summarize it? What conclusions can be made about...
After reading the following article, how would you summarize it? What conclusions can be made about Amazon? Case 12: Amazon.com Inc.: Retailing Giant to High-Tech Player? (Internet Companies) Overview Founded by Jeff Bezos, online giant Amazon.com, Inc. (Amazon), was incorporated in the state of Washington in July 1994, and sold its first book in July 1995. In May 1997, Amazon (AMZN) completed its initial public offering and its common stock was listed on the NASDAQ Global Select Market. Amazon quickly...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT