Webbserv1: Källkod
Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/exercises/

dbtestforfattare.php
formular1.php
formular2.php
formular3.php
formular4.php
funktioner1-5.php
hej3.php
hej4.php
hej_svejs.php
index.php
ovngrunder1-4.php
sida1.php
sida2.php
sida3.php
sidslut.php
sidstart.php
uppgiftinklfiler.php
valkommen1.php
valkommen2.php

funktioner1-5.php

90 lines UTF-8 Windows (CRLF)
<!DOCTYPE html>
<html lang="sv">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

<H2>1.</H2>
<br>
<?php
function hejsvejs() {
    echo 
"Hejsvejs!<br>";
}

hejsvejs();
?>
<br>
<h2>2.</h2>
<br>
<?php
function hejsvejsFlera($antal) {
    for (
$i = 0; $i < $antal; $i++) {
        echo 
"Hejsvejs!<br>";
    }
}

hejsvejsFlera(5); 
?> <br>
<h2>3.</h2>
<br>
<?php
function storst($a, $b, $c) {
    
$max = $a;
    if (
$b > $max) {
        
$max = $b;
    }
    if (
$c > $max) {
        
$max = $c;
    }
    return 
$max;
}

$resultat = storst(12, 47, 30);
echo 
"Det största talet är: $resultat";  
?>
<br>
<h2>4.</h2>
<br>
<?php
function storstEllerMinst($a, $b, $c, $lage = "") {
    
$max = $a;
    
$min = $a;

    if (
$b > $max) $max = $b;
    if (
$c > $max) $max = $c;

    if (
$b < $min) $min = $b;
    if (
$c < $min) $min = $c;

    if (
$lage == "minsta") {
        return 
$min;
    }
    return 
$max;
}

$a = storstEllerMinst(12, 47, 30);              
$b = storstEllerMinst(12, 47, 30, "minsta");  

echo 
"Största: $a<br>";
echo 
"Minsta: $b<br>"; ?>
<br>
<h2>5.</h2>
<?php
function medelvarde($arr) {
    
$summa = 0;
    foreach (
$arr as $v) {
        
$summa += $v;
    }
    return 
$summa / count($arr);
}

$tal = [4, 8, 15, 16, 23, 42];
$medel = medelvarde($tal);

echo 
"Medelvärdet är: $medel"; ?>
    
</body>
</html>


Document