<?php
//
// Bibliothèque de fonctions PHP
//
//___________________________________________________________________
/**
* Envoie à la sortie standard le début du code HTML d'une page
*
* @param string $titre Titre de la page
*/
function htmlDebut($titre) {
$titre = htmlentities($titre, ENT_COMPAT, 'ISO-8859-1');
echo '<!DOCTYPE html>',
'<html>',
'<head>',
'<meta charset="ISO-8859-1">',
'<title>', $titre, '</title>',
'<style>',
'body { font-size: 13px;',
'font-family: Verdana, sans-serif}',
'h3 { font-size: 15px;',
'margin: 0 0 15px 0;',
'padding: 5px 0;',
'text-align: center;',
'background: #FFF5AB}',
'h4 { font-size: 13px;',
'margin: 1em 0 0 0;',
'padding: 3px;',
'background: #ebebeb}',
'</style>',
'</head>',
'<body>',
'<h3>', $titre, '</h3>';
}
//___________________________________________________________________
/**
* Envoie à la sortie standard la fin du code HTML d'une page
*/
function htmlFin() {
echo '</body></html>';
}
//___________________________________________________________________
/**
* Testeur de fonction
*
* @param string arg[0] nom de la fonction à tester
* @param mixed arg[1 à n-1] paramètres à passer à la fonction
* @param mixed arg[n] résultat attendu
*/
function tester() {
$args = func_get_args();
if (count($args) < 3) {
echo '<hr>La fonction tester doit avoir ',
'au moins 3 paramètres.';
return;
}
$fonction = array_shift($args);
$attendu = array_pop($args);
$retour = call_user_func_array($fonction, $args);
$iMax = count($args);
echo '<hr><span style="color:',
($retour === $attendu) ? 'green' : 'red', '">',
'<b>', $fonction, '</b></span>',
'<br>Paramètre', ($iMax > 1) ? 's : ' : ' : ';
for ($i = 0; $i < $iMax; $i++) {
echo '<span style="background:#ebebeb;margin:0 5px;">';
var_dump($args[$i]);
echo '</span>';
}
echo '<br>Attendu : ';
var_dump($attendu);
echo '<br>Retourné : ';
var_dump($retour);
}
?>