How to convert a character inside string to uppercase in PHP

1 Answer

0 votes
function char_to_uppercase(&$s, $idx) { 
    if ($idx < 0 || $idx > strlen($s)) {
        return;
    }
  
    for ($i = 0; $i < strlen($s); $i++) {
         if ($i == $idx) {
             $s[$i] = strtoupper($s[$i]);
         }
    }
}
  
$s = "php programming";

char_to_uppercase($s, 0);
echo $s . "<br />";

char_to_uppercase($s, 5);
echo $s; 
  
 
         
  
/*
run:
              
Php programming
Php pRogramming
       
*/

 



answered Nov 19, 2019 by avibootz

Related questions

1 answer 155 views
2 answers 260 views
1 answer 211 views
4 answers 328 views
1 answer 188 views
1 answer 146 views
...