|
|
|
| Php-Convertir un entier sous la forme 01,02.. par Olive33 |
vendredi 9 mai 2008 à 23:42:21 |
Configuration: Windows 2000 Firefox 2.0.0.14
Bjr
Utilise la fonction str_pad() de PHP http://fr2.php.net/manual/fr/function.str-pad.php exemple : <html>
<head>
</head>
<body>
<?php
// Complète une chaîne par la gauche avec des zéros selon la taille spécifiée
function lpad_zero($chaine,$taille)
{
return str_pad($chaine,$taille,"0",STR_PAD_LEFT);
}
$a=1;
echo lpad_zero($a,2);
?>
</form>
</body>
</html>--
PhP Il y a 10 types de personnes dans le monde : ceux qui comprennent le binaire et les autres ...
|
Oui certe mais je pensais plus à une truc du genre
<?php
// Complète une chaîne par la gauche avec des zéros selon la taille spécifiée
function lpad_zero($chaine,$taille)
{
return str_pad($chaine,$taille,"0",STR_PAD_LEFT);
}
function difheure($heuredeb,$heurefin)
{
$hd=explode(":",$heuredeb);
$hf=explode(":",$heurefin);
$hd[0]=(int)($hd[0]);$hd[1]=(int)($hd[1]);$hd[2]=(int)($hd[2]);
$hf[0]=(int)($hf[0]);$hf[1]=(int)($hf[1]);$hf[2]=(int)($hf[2]);
if($hf[2]<$hd[2]){$hf[1]=$hf[1]-1;$hf[2]=$hf[2]+60;}
if($hf[1]<$hd[1]){$hf[0]=$hf[0]-1;$hf[1]=$hf[1]+60;}
if($hf[0]<$hd[0]){$hf[0]=$hf[0]+24;}
return (lpad_zero($hf[0]-$hd[0],2).":".lpad_zero($hf[1]-$hd[1],2).":".lpad_zero($hf[2]-$hd[2],2));
}
$hdeb1="01:00:00";
$hfin1="02:00:00";
$jour1 = difheure($hdeb1,$hfin1);
echo $jour1;
?>
Autre variante en utilisant uniquement sprintf() <?php
function difheure($heuredeb,$heurefin)
{
$hd=explode(":",$heuredeb);
$hf=explode(":",$heurefin);
$hd[0]=(int)($hd[0]);$hd[1]=(int)($hd[1]);$hd[2]=(int)($hd[2]);
$hf[0]=(int)($hf[0]);$hf[1]=(int)($hf[1]);$hf[2]=(int)($hf[2]);
if($hf[2]<$hd[2]){$hf[1]=$hf[1]-1;$hf[2]=$hf[2]+60;}
if($hf[1]<$hd[1]){$hf[0]=$hf[0]-1;$hf[1]=$hf[1]+60;}
if($hf[0]<$hd[0]){$hf[0]=$hf[0]+24;}
return sprintf("%02s:%02s:%02s",$hf[0]-$hd[0],$hf[1]-$hd[1],$hf[2]-$hd[2]);
}
$hdeb1="01:00:00";
$hfin1="02:00:00";
$jour1 = difheure($hdeb1,$hfin1);
echo $jour1;
?>
Think different, think php ... ;-) PhP Il y a 10 types de personnes dans le monde : ceux qui comprennent le binaire et les autres ...
|
| 23/03 03h47 | PHP, HTML et Formulaire | Programmation | 29/04 18h22 | 6 |
| 09/03 20h38 | conversion en format PDF help!!! | Windows | 09/03 20h45 | 1 |
| 22/02 10h32 | [PHP] et les formulaires | Programmation | 04/03 13h43 | 4 |
| 02/01 23h37 | conversion du format pdf en word | Logiciels/Pilotes | 03/01 00h15 | 4 |
| 24/06 14h56 | Convertir les formats d'image | Infographie/Photo | 24/06 15h45 | 3 |