Question

Must be done in PHP. Details below:

NOTE: in #4 part B, the split function that my teacher wants me to use in this program is: str_split()

1. Create a new document in your text editor (notepad++) 2. Type the <html element, header information, and <body element. Use String Manipulation functions as the content of the <title element 3. Add the following standard PHP script delimiters to the document body: ?php 4. In the php script section write the appropriate statements to accomplish the following: a. Assign the following string to a variable wi january 31 wi february 28 sp march 31:sp apri l 30 sp may 3 1:su june 30 su july 31: su august 31: fa september 30 fa octobe r 31: fa november 30 wi december 31 Notice that the sting is made up of the months of the year separated by the colon character. The month names are preceded with three characters. The first two characters are the abbreviation of the season wi for winter sp for spring, su for summer and fa for fall) and the third character is the underscore C) character. The month names are also followed by three characters. The first one is the underscore L) character and the other two are the number of days that the month has. There are no spaces inside the string b. Using the appropriate string function split the string to create an array. The separator is the colon character. The array variable should be named $months. (Pages 151-153 in the book about creating an array from a sting). After you successfully create the array, the first element of the array will be wi january 31, the second wi february 28 the third sp march 31 and the last one wi december 31. c. Using the basic syntax of the foreach statement loop through the array that you have created above. Inside the loop, write the appropriate statements to display the following information using unordered list (ul tag) January Season: Winter Number of Days: 3

0 0
Add a comment Improve this question Transcribed image text
Answer #1
<?php
$s_months = "wi_january_31:wi_february_28:sp_march_31:sp_april_30:sp_may_31:su_june_30:su_july_31:su_august_31:fa_september_30:fa_october_31:fa_november_30:wi_december_31";
//-- Created an array with season
$a_seasons = array("wi"=>"winter", "sp"=>"spring", "su"=>"summer", "fa"=>"fall");
//-- split it in to an array
$months = split(":", $s_months);
?>
<html>
    <head>
        <title>String Manipulation Functions</title>
    </head>
    <body>
        <h1>String Manipulation Functions</h1>
        <?php foreach($months as $keys=>$values) {
            $a_calenders = split("_", $values);
            if (!empty($a_calenders))
            {
                //Swapping array elements in order to get month name.
                $temp = $a_calenders[0];
                $a_calenders[0] = $a_calenders[1];
                $a_calenders[1] = $temp;
                foreach($a_calenders as $k=>$v)
                {
            ?>
        <ul>
            <?php if($k == 0){ ?><li><?php echo ucfirst($v); ?> </li> <?php } ?>
            <?php if($k == 1 and array_key_exists($v, $a_seasons)){ ?><li style="list-style-position: inside;
            text-align: inherit;"><?php echo "Season: ".ucfirst($a_seasons[$v]); ?> </li> <?php } ?>
            <?php if($k == 2){ ?><li style="list-style-position: inside;
            text-align: inherit;"><?php echo "Number of Days: ".ucfirst($v); ?> </li> <?php } ?>
        </ul>
        <?php }
            }
         } ?>
    </body>
</html>

Sample Output:

  • January
    • Season: Winter
    • Number of Days: 31
  • February
    • Season: Winter
    • Number of Days: 28
  • March
    • Season: Spring
    • Number of Days: 31

.... and so on.

Note: You can't use str_split() method for string delimiter. it accept only length i.e integer should be used for 2 paramter. Syntax: str_split(stringvariable, length). Eg: str_split($str, 2). Here delimiter is string (:) not an interger.

So i used split() method is the one type of string function.

Add a comment
Know the answer?
Add Answer to:
Must be done in PHP. Details below: NOTE: in #4 part B, the split function that...
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
  • <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 8 Hands-on Project 8-1 Author: Date:   ...

    <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 8 Hands-on Project 8-1 Author: Date:    Filename: index.htm --> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <title>Hands-on Project 8-1</title> <link rel="stylesheet" href="styles.css" /> <script src="modernizr.custom.65897.js"></script> </head> <body> <header> <h1> Hands-on Project 8-1 </h1> </header> <article> <h2>New Account Information</h2> <form> <fieldset id="deliveryinfo"> <label for="fnameinput">First Name</label> <input type="text" id="fnameinput" name="fname" /> <label for="lnameinput">Last Name</label> <input type="text" id="lnameinput" name="lname" /> <label for="addrinput">Street Address</label> <input type="text" id="addrinput" name="address" /> <label for="cityinput">City</label> <input type="text" id="cityinput" name="city"...

  • NEED HELP with HTML with Javascript embedding for form validation project below. I have my code...

    NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due...

    i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due Sunday, 19 May 2019, 11:59 PM Due Friday, 24 May 2019, 11:59 PM Part B: Minimum Submission Requirements Ensure that your Lab4 folder contains the following files (note the capitalization convention): o Diagram.pdf o Lab4. asm O README.txt Commit and push your repository Lab Objective In this lab, you will develop a more detailed understanding of how...

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