is115-php/common.php

53 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2021-08-23 10:41:53 +02:00
<?php
$re = '/([0-9]{1,2})/m';
$request = explode('/', $_SERVER['PHP_SELF']);
preg_match_all($re, $request[ count($request)-1], $matches, PREG_SET_ORDER, 0);
$modulNr = $matches[0][0];
$oppgNr = $matches[1][0];
function getNavigation(): string {
global $modulNr, $oppgNr;
$returnArr = [];
if($oppgNr > 1 && file_exists("index".$modulNr."_".($oppgNr-1).".php")){
$returnArr[] = "<a href='index".$modulNr."_".($oppgNr-1).".php'>Oppgave ".($oppgNr-1)."</a>";
}
$returnArr[] = "<a href='./'>Tilbake til modulen</a>";
if(file_exists("index".$modulNr."_".($oppgNr+1).".php")){
$returnArr[] = "<a href='index".$modulNr."_".($oppgNr+1).".php'>Oppgave ".($oppgNr+1)."</a>";
}
return implode(' - ', $returnArr);
}
function title(): string {
global $modulNr, $oppgNr;
return "Modul ".$modulNr." - Oppgave $oppgNr";
}
function higher($int1, $int2): int {
if($int1 >= $int2){
return $int1;
}
return $int2;
}
function lower($int1, $int2): int {
if($int1 < $int2){
return $int1;
}
return $int2;
2021-09-22 20:45:08 +02:00
}
function str_lreplace($search, $replace, $subject){
$pos = strrpos($subject, $search);
if($pos !== false){
$subject = substr_replace($subject, $replace, $pos, strlen($search));
}
return $subject;
}