Advertisement
RGeorgiev97

Untitled

Mar 19th, 2020
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.08 KB | None | 0 0
  1. <?php
  2.  
  3. $wantedName = readline();
  4. $input = readline();
  5.  
  6. while ($input !== 'Sign up') {
  7.     $args = explode(' ', $input);
  8.     $command = $args[0];
  9.     switch ($command) {
  10.  
  11.         case 'Case':
  12.             $type = $args[1];
  13.             if ($type == 'lower') {
  14.                 $wantedName = strtolower($wantedName);
  15.                 echo $wantedName . PHP_EOL;
  16.             }
  17.             if ($type == 'upper') {
  18.                 $wantedName = strtoupper($wantedName);
  19.                 echo $wantedName . PHP_EOL;
  20.             }
  21.             break;
  22.  
  23.         case 'Reverse':
  24.             $startIndex = $args[1];
  25.             $endIndex = $args[2];
  26.             $lenght = $endIndex-$startIndex+1;
  27.             if ($startIndex >= 0 && $startIndex < strlen($input) && $endIndex >= 0 && $endIndex < strlen($input)) {
  28.                 $subString = substr($wantedName, $startIndex, $lenght);
  29.                 $subString = strrev($subString);
  30.                 echo $subString . PHP_EOL;
  31.             }
  32.             break;
  33.  
  34.         case 'Cut':
  35.             $cutSubstring = $args[1];
  36.             str_replace($cutSubstring, '', $wantedName, $count);
  37.             if ($count > 0) {
  38.                 $wantedName = str_replace($cutSubstring, '', $wantedName);
  39.                 echo $wantedName . PHP_EOL;
  40.             } else {
  41.                 echo "The word $wantedName doesn't contain $cutSubstring." . PHP_EOL;
  42.             }
  43.             break;
  44.  
  45.         case 'Replace':
  46.             $char = $args[1];
  47.             $wantedName = str_replace($char, '*', $wantedName);
  48.             echo $wantedName . PHP_EOL;
  49.             break;
  50.  
  51.         case 'Check':
  52.             $char = $args[1];
  53.             $valid = false;
  54.             for ($i = 0; $i < strlen($wantedName); $i++) {
  55.                 if ($wantedName[$i] == $char) {
  56.                     $valid = true;
  57.                 }
  58.             }
  59.             if ($valid) {
  60.                 echo 'Valid' . PHP_EOL;
  61.             } else {
  62.                 echo "Your username must contain $char." . PHP_EOL;
  63.             }
  64.  
  65.             break;
  66.     }
  67.  
  68.     $input = readline();
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement