PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 20, 2022

[FIXED] How to converts the string to alternate upper and lower case in php (Laravel Zero)?

 February 20, 2022     command-line-interface, input, laravel, php, string     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing