October 2009
Beginner
836 pages
19h 37m
English
The trick here is to make a second call to date(), passing in the appropriate characters to display the current date. Here's how you might write the script (including comments where appropriate):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Hello</title>
<link rel="stylesheet" type="text/css" href="common.css" />
</head>
<body>
<h1>
<?php
// Get the current time in a readable format
$currentTime = date( "g:i:s a" );
// Get the current date in a readable format
$currentDate = date( "M j, Y" );
// Display greeting, time and date to the visitor
echo "Hello, world! The current time is $currentTime on $currentDate";
?>
</h1>
</body>
</html>Write a PHP script such as this:
<?php $x = 5; $x = $x + 1; $x += 1; $x++; echo $x; ?>
Write a PHP script such as this:
<?php $x = 3; $y = 4; echo "Test 1 result: " . ($x == $y) . "<br />"; echo "Test 2 result: " . ($x > $y) . "<br />"; echo "Test 3 result: " . ($x <= $y) . "<br />"; echo "Test 4 result: " . ($x != $y) . "<br />"; ?>
You could write this script many ways. The following solution creates a for loop to count the numbers, then uses the ? (ternary) operator and a switch construct to determine if each number is odd, even, or prime.
<!DOCTYPE html PUBLIC "-//W3C//DTD ...
Read now
Unlock full access