Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you will create a script that uses comparison operators and functions to compare two strings to see if they are the same.

In this assignment, you will create a script that uses comparison operators and functions to compare two strings to see if they are the same.

1. Create a new PHP document namedCompareStrings.phpin your IDE.

2. Type the declaration, element, document head, and element. Use the string Compare Strings as the content of the element. </p> </div> <p dir="ltr"> </p> <div align="left" id="mobile-question-style"> <p dir="ltr"><!DOCTYPE html> </p> </div> <p dir="ltr"> </p> <div align="left" id="mobile-question-style"> <p dir="ltr"><html> </p> </div> <p dir="ltr"> </p> <div align="left" id="mobile-question-style"> <p dir="ltr"><head> </p> </div> <p dir="ltr"> </p> <div align="left" id="mobile-question-style"> <p dir="ltr"><title>Compare Strings

//ADD CODE HERE

3. Add the following text and elements to the document body:

Compare Strings


4. Add the following script section to the document body:

?>

5. In the PHP section, declare and initialize two string variables:

$firstString = "Geek2Geek";

$secondString = "Geezer2Geek"

6. Write an if statement that test if both variables $firstString and $secondString are not empty(). If both variables are not empty write a nested second if statement that uses the comparison operator (==) or the functionstrcmp() to determine if both strings are the same. If the strings are the same call the sameVar() function. If the strings are not the same call the diffVar() function.

7. Create two PHP functions: samevar() and diffVar().

ThesameVar() function will accept two arguments:sameVar($var1,$var2) { }. The function will print a statement statingstring $var1 does match $var2.

The diffVar() function will accept two arguments:diffVar($var1,$var2) { }. The function will print a statement statingstring $var1 does not match $var2.

8. At the end of the script section, add the following else clause, which executes if either the $firstString or the $secondString contains an empty value.

else {

echo "

Either the \$firstString variable or the \$secondString variable does not contain a value so the two strings cannot be compared.

";

}

9. Save the document as CompareStrings.php and upload the file to the server to the module4a directory.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Neo4j Data Modeling

Authors: Steve Hoberman ,David Fauth

1st Edition

1634621913, 978-1634621915

More Books

Students also viewed these Databases questions

Question

c. What were you expected to do when you grew up?

Answered: 1 week ago

Question

d. How were you expected to contribute to family life?

Answered: 1 week ago

Question

e. What do you know about your ethnic background?

Answered: 1 week ago