How to swap two different characters in a string with PHP

1 Answer

0 votes
$s = "php programming";
 
$s = strtr($s, array('r' => 'p', 'p' => 'r'));

echo $s;
 
 
 
 
/*
run:
  
rhr rpogpamming
  
*/

 



answered Sep 24, 2021 by avibootz

Related questions

...