PHP
RasBlazed
-
jisisv Messages postés 3678 Statut Modérateur -
jisisv Messages postés 3678 Statut Modérateur -
Bjour,
je voudrais savoir comment tester en php si un nombre contient 1 ou 2 chiffres.
Par ex. detecter si c'est un 3 ou 03
Merci
RasBlazed
je voudrais savoir comment tester en php si un nombre contient 1 ou 2 chiffres.
Par ex. detecter si c'est un 3 ou 03
Merci
RasBlazed
2 réponses
-
Salut,
regarde du coté de la fonction strlen() :
http://fr2.php.net/manual/fr/function.strlen.php
et pour t'assurer que c'est bien un nombre qui a été rentré :
http://fr2.php.net/manual/fr/function.is-numeric.php
Bon week end -
Ne pas confondre le contenu d'une variable et la manière dont on l'affiche:
johand@horus:~/tmp$ cat brol.php <?php $myInt = 23; printf("%3d\n", $myInt); printf("%03d\n", $myInt); printf("%+4d\n", $myInt); ?> johand@horus:~/tmp$ php brol.php 23 023 +23
Voir les formats ici par exemple
http://php.easynet.be/manual/fr/function.sprintf.php
Johan