Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $saisie = 1+1;2*2;3/3; // 7
- $chiffres = explode(';',$saisie);
- for($i=0;$i<count($chiffres);$i++)
- {
- $addition = strpos("+",$chiffres[$i]);
- $soustraction = strpos("-",$chiffres[$i]);
- $multiplication = strpos("*",$chiffres[$i]);
- $division = strpos("/",$chiffres[$i]);// 1+1
- if(is_numeric($addition)) // si c'est un chiffre OU if($addition!=false)
- {
- $operation = explode("+",$chiffres[$i]);
- $resultat = $operation[0]+$operation[1];
- // 1) Je veux sue tu fasses un explode() du caractère en question :
- /*
- C'est à dire que si j'ai trouvé un "+", alors tu vas faire un $operation = explode("+",$chiffres[$i])
- ton premier chiffre => $operation[0] ;
- ton deuxieme chiffre => $operation[1];
- $resultat = $operation[0] + ....
- */
- }
- if(is_numeric($soustraction))
- {
- $operation = explode("-",$chiffres[$i]);
- $resultat = $operation[0]-$operation[1];
- }// Pareil pour les trois autres
- if(is_numeric($multiplication))
- {
- $operation = explode("*",$chiffres[$i]);
- $resultat = $operation[0]*$operation[1];
- }
- if(is_numeric($division))
- {
- $operation = explode("/",$chiffres[$i]);
- $resultat = $operation[0]/$operation[1];
- }
- echo "Le resultat est de $resultat ";
- }
- ?>
Add Comment
Please, Sign In to add comment