SEC S20W6 || Date & Time Types And String Predefined Methods in PHP

Hi friends, after reading around I am interested in participating in an amazing challenge this week. The challenge is titled: Date & Time Types And String Predefined Methods in PHP by Mr. @kouba01 and Mr. @starrchris following the contest link: SEC S20W6 || Date & Time Types And String Predefined Methods in PHP

0001-5806710013764503686.jpg

Previously I also invited other friends such as Mr. @irawandedy, Mr @muzack1 , sir @sisol, sir @aneukpineung78 and my friend @cymolan.

Task1: (1points)
Here’s a multiple-choice quiz (QCM) focused on PHP date and time functions, indicate the correct answer, and explain your choice.

  1. What is checkdate function in PHP?
    Then the answer I think is correct is: B. Checks whether a date is valid based on the day, month, and year.
    The reason is that have we ever thought if you want to check if February 30, 2024 is a valid date? Well, this is where checkdate() comes into play. It's like a doorman that won't let you through if the date is wrong. Just input the day, month, and year, and it will say "Yes, this is valid" or "Nope, invalid!"

  2. If the date is not timestamped, what will be returned?
    Then the correct answer in my opinion is : A. The current system date and time as a formatted string.
    The reason for this is that think of date() like a best friend who is always updated with the current time. If it's not given a timestamp, it will automatically look at the clock in its hand and say, "It's this date, this time, friend!" so it will tell us the current date and time in the format we requested.

  3. Which statement is true about the mktime function in PHP?
    The correct answer in my opinion is: B. Generates a timestamp based on the given hour, minute, second, day, month, and year values.
    With the reason that: mktime() is like a time machine, so it can take us to a certain moment by telling us the hour, minute, second, day, month, and year.

  4. What is the purpose of strtotime in PHP?
    The answer that I think is correct is, B. Converting an English date string into a Unix timestamp.
    Reason: strtotime() is like a translator from date words such as "next Monday" or "2024-10-16" to timestamp code that computers understand.

Task2: (3points)
By applying String Functions, complete each code in the table below to achieve the requested result:

2.a

image.png

Here we utilize strlen(), while the strlen($ch) function itself will be utilized to calculate the length of the $ch string. At the origin the result is 28: The string "we study the php and css...." is 28 characters long without modification. So why add spaces? Yes, the goal is to ask for a result of 30, then we can utilize 2 additional spaces in the string, so the result is :

image.png

2.b

image.png

Here we utilize trim() which will remove the spaces at the beginning and end of the $ch string.
The result:
image.png

2.c

image.png

Here we utilize str_replace() which function str_replace('.', '', $ch) it will replace all periods (.) inside the string with an empty string (''). That is, all periods will be removed.
The result:

image.png

2.d

image.png

First utilize strpos() whose function is to find the position of the @ character in the string and we add 1 so that its position matches human counting (1-indexed). Next utilizing substr() with the purpose of taking the substring of the $adress string, so that it starts from the position after @, so that we get domaine.fr.

And the result is :

image.png

2.e

image.png

First, we declare the variable $ch in order to store a string containing a sentence with the word "person". Next there will be an explanation message. While replacing the word we use str_replace() so that it replaces all occurrences of "person" with "walictd". as for displaying the results we only use nl2br($ch) in order to maintain the format of the new line so that it appears properly in the browser.

And the result:
image.png

2.f

image.png

First we declare variables such as $name in order to store the real name "Starrchris", then $mail in order to store the email address "[email protected]". Then we will change the letters where strtoupper($name) will be used to change all letters in the name to capital letters, then the results will be stored in $name_upper. While strtolower($mail) will be used to change all letters in the email address to lowercase, and the results are stored in $mail_lower.

The result:
image.png

2.g

image.png

First we will declare a variable on $ch to store the original string e.g. "STEEMIT". then we will reverse the String on strrev($ch) utilized to reverse the order of characters in the string. The result is stored in the variable $reversed. The result:

image.png

Project: (6 points)
A company provides its clients with a leisure equipment rental service. For this, a simplified version of a website is proposed that allows:

The rental of equipment,
The recording of the return of rented equipment,
The editing of daily rental statistics.

I will complete this project as best I can, although it is not 100% the same, I will try to be as similar as possible. First I will create a database first. Here's the process:

Turn on Xampp so that it can run localhost programs and pages.
image.png

Next, I just created the database by visiting phpmyadmin. Then on the database menu I chose SQL.

image.png

Then there we will enter this code to create the database.

image.png

Now that the database has been created, let's see the results of each table.

image.png

Contents of the client table

image.png

Fill in the equipment table

image.png

Fill in the rental table

image.png

Then we create the html file as below.

index_html.jpg

then I created a Location.html file

Location_html.jpg

Then create a Location.php file

Location_php.jpg

Here's the Retour.php file

Retour_php.jpg

Here's the Return.html file

Return_html.jpg

Statistics.html file

Statistics_html.jpg

Statistics.php file

Statistics_php.jpg

I also created a css file.

css_.jpg

Then we run the code:

Desain tanpa judul (3).gif

Best Regard
@walictd
baawah.png

Sort:  
Loading...

This post has been upvoted/supported by Team 5 via @httr4life. Our team supports content that adds to the community.

image.png

Thank you so much