Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,926 questions

51,859 answers

573 users

How to convert a string lowercase characters to uppercase and uppercase to lowercase with PHP

3 Answers

0 votes
$s = "Php ProGRamMinG";

$s = strtolower($s) ^ strtoupper($s) ^ $s;

echo $s; 
  
 
         
  
/*
run:
              
pHP pROgrAMmINg
       
*/

 



answered Nov 19, 2019 by avibootz
0 votes
$s = "Php ProGRamMinG";

$s = preg_replace_callback(
    '/[a-z]/i',
    function($same_chars) {
        return $same_chars[0] ^ ' ';
    },
    $s
);

echo $s; 
  
 
         
  
/*
run:
              
pHP pROgrAMmINg
       
*/

 



answered Nov 19, 2019 by avibootz
0 votes
function flip_characters($s) {
    for ($i = 0; $i < strlen($s); $i++) {
         $ch = ord($s[$i]);
         if (($ch >= 65 && $ch <= 90) || ($ch >= 97 && $ch <= 122)) {
              $s[$i] = chr($ch ^ 32);
         }
    }
    return $s;
}

$s = "Php ProGRamMinG";

$s = flip_characters($s);

echo $s; 
  
 
         
  
/*
run:
              
pHP pROgrAMmINg
       
*/

 



answered Nov 19, 2019 by avibootz
...