Skip to content

Instantly share code, notes, and snippets.

@niquedegraaff
Created February 11, 2012 16:13
Show Gist options
  • Save niquedegraaff/1801556 to your computer and use it in GitHub Desktop.
Save niquedegraaff/1801556 to your computer and use it in GitHub Desktop.
School - PHP - Week 2
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="utf-8">
<title>Week 1 - Activiteit 4 - Omrekenen Celcius naar Fahrenheit</title>
</head>
<body>
<?php
/**
* @author Dominique de Graaff
* @since 11-02-2012
*/
// Data & Logic
$celcius = 20;
$fahrenheit = round(((9 / 5) * $celcius) + 32);
// Output
echo "<p>Temperatuur in Celsius: $celcius &deg;C. </p>\n";
echo "\t\t<p>Temperatuur in Fahrenheit: $fahrenheit &deg;F. </p>";
?>
</body>
</html>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="utf-8">
<title>Week 1 - Activiteit 5 - Omrekenen Fahrenheit naar Celsius</title>
</head>
<body>
<?php
/**
* @author Dominique de Graaff
* @since 11-02-2012
*/
// Data & Logic
$fahrenheit = 68;
$celcius = round(($fahrenheit - 32) * (5 / 9));
// Output
echo "<p>Temperatuur in Fahrenheit: $fahrenheit &deg;F. </p>\n";
echo "\t\t<p>Temperatuur in Celsius: $celcius &deg;C. </p>";
?>
</body>
</html>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="utf-8">
<title>Week 1 - Activiteit 6 - Euro's omzetten naar centen</title>
<style type="text/css">
span { display: inline-block; width: 200px; }
</style>
</head>
<body>
<?php
/**
* @author Dominique de Graaff
* @since 11-02-2012
*/
// Variables
$euros = 4.46;
$cents = 100 * $euros;
// Output
echo "<h1>Euro's naar centen</h1>\n";
echo "\t\t&euro; ". str_replace('.', ',', $euros) . " = $cents centen.";
?>
</body>
</html>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="utf-8">
<title>Week 1 - Activiteit 7 - Centen omzetten naar Euro's</title>
<style type="text/css">
span { display: inline-block; width: 200px; }
</style>
</head>
<body>
<?php
/**
* @author Dominique de Graaff
* @since 11-02-2012
*/
// Variables
$cents = 446;
$euros = $cents / 100;
// Output
echo "<h1>Centen naar Euro's</h1>\n";
echo "\t\t $cents centen = &euro; ". str_replace('.', ',', $euros);
?>
</body>
</html>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="utf-8">
<title>Week 1 - Activiteit 8 - Haal datum uit 14042010 int variable</title>
<style type="text/css">
span { display: inline-block; width: 200px; }
</style>
</head>
<body>
<?php
/**
* @author Dominique de Graaff
* @since 11-02-2012
*/
// Variables
$date = (int)"07042012";
// Logic Method 1 (strict to % and / only)
$day1 = $date % 100000000 / 1000000 % 1000000;
$month1 = $date % 1000000 / 10000 % 10000;
$year1 = $date % 10000;
// Logic Method 2 (using floor method)
$day2 = floor($date / 1000000);
$month2 = floor(($date % 1000000) / 10000);
$year2 = $date % 10000;
// Output
echo "<h1>Haal datum uit \"\$date = $date;\"</h1>";
echo "\t\t
<p>
<strong>Antwoorden:</strong><br/>
Methode 1: " . $day1 . "-" . $month1 . "-" . $year1 . " <br/>
Methode 2: " . $day2 . "-" . $month2 . "-" . $year2 . "
</p>\n";
?>
</body>
</html>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="utf-8">
<title>Week 1 - Activiteit 9 - Wat doet de time() functie?</title>
<style type="text/css">
span { display: inline-block; width: 200px; }
</style>
</head>
<body>
<?php
/**
* @author Dominique de Graaff
* @since 11-02-2012
*/
// Variables
$time = time();
// Output
echo ("<h1>\"echo time();\" geeft: $time</h1>\n");
echo ("\t\t
<p>
<strong>Uitleg:</strong><br/>
Met time() functie krijg je een UNIX timestamp terug. <br/>
Dit zijn het aantal seconden sinds 1 januari 1970.
</p>\n");
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment