Question

PHP Program Complete PHP code (and HTML Code) Using functions to abstract the logic away from...

PHP Program

Complete PHP code (and HTML Code)

Using functions to abstract the logic away from the rest of your code makes it easier to read and maintain. PHP provides a number of useful functions as standard, and this week you will use some of these functions to obtain information.

Create a program that compares two strings provided on an HTML form, and determine if the two strings are anagrams. The HTML page asks the user for the input strings, and the PHP program will generate another HTML page with the result. For example:

Enter string #1: NOTE
Enter string #2: TONE

"NOTE" and "TONE" are anagrams

You should also check that the two strings are of the same length before attempting to evaluate them as anagrams.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If u have any doubts please comment

<?php
if(isset($_POST['check'])){
   if((!empty($_POST['word1'])) && (!empty($_POST['word2']))) {
   $string_1=strtoupper($_POST['word1']);
   $string_2=strtoupper($_POST['word2']);

function anagram($string_1, $string_2){
if(strlen($string_1)==(strlen($string_2))){
   if (count_chars($string_1, 1) == count_chars($string_2, 1)) {
       echo "Enter String #1 : <b>".$string_1."</b></br>";
       echo "Enter String #2 : <b>".$string_2."</b></br>";
   echo '<b>"'.$string_1.'"</b> and <b>"'.$string_2.'"</b> are anagrams';
   }else{
   echo "Enter String #1 : <b>".$string_1."</b></br>";
       echo "Enter String #2 : <b>".$string_2."</b></br>";
   echo '<b>"'.$string_1.'"</b> and <b>"'.$string_2.'"</b> are not an anagrams';
   }
}else{
   echo"<script>alert('Words Should be same length')</script>";
}

   }
   anagram($string_1,$string_2);
}else{
   echo"<script>alert('All fields are required')</script>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
   <title>Chegg</title>
</head>
<body>
  
<form action="?" method="POST">
   <input type="text" name="word1" placeholder="Word1" required=""><br><br>
   <input type="text" name="word2" placeholder="Word2" required=""><br><br>
   <button type="submit" name="check">Check Anagram</button><br><br>
</form>

</body>
</html>

Output :

Add a comment
Know the answer?
Add Answer to:
PHP Program Complete PHP code (and HTML Code) Using functions to abstract the logic away from...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python Code Write a program using functions and mainline logic which prompts the user to enter...

    Python Code Write a program using functions and mainline logic which prompts the user to enter a number. The number must be at least 5 and at most 20. (In other words, between 5 and 20, inclusive.) The program then generates that number of random integers and stores them in a list. The random integers should range from 0 to 100. (You can use a wider range if you want, but the lower end of the range must be at...

  • Complete the Rectangle Program Using the code given in rectangle.cpp, implement the functions that are called...

    Complete the Rectangle Program Using the code given in rectangle.cpp, implement the functions that are called in the main function to complete the program. You must not change any of the existing code in the file. You can only add functions and comments to the code. Here’s a sample run of how the program should behave: Enter rectangle length: -1 ← invalid value, ask user to re-enter Enter rectangle length: -2 ← invalid value Enter rectangle length: 0 ← invalid...

  • This program should be run on Visual Studio. Please use printf and scanf as input and output. Tha...

    This program should be run on Visual Studio. Please use printf and scanf as input and output. Thank you 6.12 Lab Exercise Ch.6b: C-string functions Create and debug this program in Visual Studio. Name your code Source.c and upload for testing by zyLabs You will write 2 functions which resemble functions in the cstring library. But they will be your own versions 1. int cstrcat(char dstDchar src) which concatenates the char array srcl to char array dstD, and returns the...

  • Objectives: Use strings and string library functions. Write a program that asks the user to enter...

    Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an empty string. The program must use the following two functions: A function called count_spaces that counts the number of white spaces inside a string. int count_space(char str[]); which tell you...

  • c++ class, coding using code blocker MinilabLoopLogic The program: You are to write a program called...

    c++ class, coding using code blocker MinilabLoopLogic The program: You are to write a program called MinilabLoopLogic which does the following Asks the user to enter 2 integers (can be one prompt or two) Gets and stores the ints Explains that the program will generate all integers that are between the numbers and are divisible by a third integer . e Asks the user for the number they should be divisible by Gets and stores that int Since 0 will...

  • using this code to complete. it python 3.#Display Program Purpose print("The program will show how much...

    using this code to complete. it python 3.#Display Program Purpose print("The program will show how much money you will make working a job that gives a inputted percentage increase each year") #Declaration and Initialization of Variables userName = "" #Variable to hold user's name currentYear = 0 #Variable to hold current year input birthYear = 0 #Variable to hold birth year input startingSalary = 0 #Variable to hold starting salary input retirementAge = 0 #Variable to hold retirement age input...

  •   Write codes that will produce the screen as shown Firstly, the program prompts user to...

      Write codes that will produce the screen as shown Firstly, the program prompts user to enter his name. Then it will display Hello <user name>. Next it prints out a menu which contains 5 options (1- add two integers, 2- add two strings, 3- compute factorial, 4- reverse a string, 5- quit program). Code all 5 tasks appropriately. When the task is completed (not including quitting program of course), the menu pops up again and asks user to try...

  • What’s the C++ code to this? So that my output is: CCTAGAATG | | X |...

    What’s the C++ code to this? So that my output is: CCTAGAATG | | X | | X | | GGACCTAAC Validity: 77.7778% Stability: 57.1429% Part #02 The goal is to write a complete C++ program that inputs 2 strings from the keyboard, where each string denotes a DNA strand such as CCTAGAATG. Assume the 2 strings are the same length. The program will then CS 109: htp:/bwww.csic.edu i109 Page I of 3 line up the two strands to see...

  • Please note that I cannot use the string library function and that it must be coded...

    Please note that I cannot use the string library function and that it must be coded in C89, thank you! Formatting: Make sure that you follow the precise recommendations for the output content and formatting: for example, do not change the text in the first problem from “Please enter a string of maximum 30 characters:” to “Enter string: ”. Your assignment will be auto-graded and any changes in formatting will result in a loss in the grade. 2.Comments: Header comments...

  • Write python code on computer, No handwritten code You will implement a program which asks the...

    Write python code on computer, No handwritten code You will implement a program which asks the user to enter scores of different courses in different semesters. The program should read the input and output some simple statistics 1. An example input string by the user is given below. Fal12016-coursel:82, course2:80,course3:85;Spring2018- course4:82;Fall2018-course5:85, course6:50, course7:78 Info from different semesters are separated by a ";", courses in each semester are separated by a,and score and corresponding course is separated by a, information of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT