Issue
i am working on Laravel Zero and created new command that will display the user input to show in uppercase and lowercase.
is there a way to also display the output alternate upper and lower case?
here is the command:
class UppercaseCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'converts';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Converts the string to uppercase, lowercase, and alternate';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$a = readline('Enter a string: ');
echo "Output in uppercase: " , strtoupper($a). PHP_EOL;
echo "Output in lowercase: " , strtolower($a);
}
/**
* Define the command's schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
public function schedule(Schedule $schedule): void
{
// $schedule->command(static::class)->everyMinute();
}
}
so how can i add new line to show the input for example like this: "hElLo wOrLd"?
Solution
The Answer:
$chars = str_split($a);
foreach($chars as $char){
if ($UpperLowerSwitch){
echo strtolower($char);
$UpperLowerSwitch = false;
}else {
echo strtoupper($char);
$UpperLowerSwitch = true;
}
}
Output(if the user insert "hello world"):
hElLo wOrLd
Answered By - Enigma
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.