Question
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
//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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started