JavaScript required
We’re sorry, but Coda doesn’t work properly without JavaScript enabled.
Skip to content
Gallery
Programming Merit Badge
Programming Merit Badge
Project 1: Python
Project 2: PHP
Project 3: HTML/CSS/Javascript
More
Share
Explore
Project 2: PHP
Intro
A popular general-purpose scripting language that is especially suited to web development. Fast, flexible and pragmatic,
PHP
powers everything from your blog to the most popular websites in the world.
Loading
www.php.net
Setup
Click on:
PHP Tryit Editor v1.2
Copy/paste this text into the left side of the screen and click “Run”:
<
html
>
<
head
>
<
title
>
Merit Badge Test
<
/
title
>
<
style
>
body
{
font
-
family
:
Helvetica
,
sans
-
serif
;
margin
:
10
px
;
background
-
color
:
#D6CEBD;
color
:
#003F87;
}
<
/
style
>
<
/
head
>
<
body
>
<
h2
>
What Time Is It
?
<
/
h2
>
<
?
php
$now
=
localtime
(
time
(
)
,
true
)
;
$num_minutes
=
$now
[
tm_min
]
;
$num_seconds
=
$now
[
tm_sec
]
;
$remaining_seconds
=
60
-
$num_seconds
;
echo
"The time is "
.
date
(
"h:i:sa"
)
;
if
(
$num_seconds
<
30
)
{
echo
'<p>First half of the minute!</p>'
;
}
else
{
echo
'<p>Second half of the minute!</p>'
;
}
echo
"There are "
.
$remaining_seconds
.
" seconds before the minute is over.<br>"
;
echo
"<hr/>"
;
echo
"<ul>"
;
for
(
$i
=
0
;
$i
<
10
;
$i
++
)
{
echo
"<li>Counting: "
.
$i
.
"</li>"
;
}
echo
"</ul>"
;
?
>
<
/
body
>
<
/
html
>
Your Turn
Make the following changes:
Copy the code that checks the seconds, and have it do the same thing with num_minutes (i.e. print first half or second half of the hour).
Add an if statement that prints “Troop 13” or “Troop 15” if the number of seconds is 13 or 15 respectively.
More Info
To learn more about PHP visit:
PHP: A simple tutorial - Manual
Intro
Setup
Your Turn
More Info
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
Ctrl
P
) instead.