code: public static function removeLastCharsFromString(string $input, int $numChars = 1): string 
      {
          if ($numChars > strlen($input)) {
              throw new \InvalidArgumentException("Cannot remove $numChars from $input");
          }
          return substr($input, 0, strlen($input) - $numChars);
      }
docs: string length must be >= numChars