title: How can I swap the values of two different characters in a string with PHP? A becomes B, B becomes A
body: <p>I have a string in PHP. I want to swap a certain character with the value from another character. If I do it my way, A becoming B will replace A with B but the already existing B values will remain the same. When I try to swap B into A, there are, of course, values that were not originally swapped, because they were already there.</p>
  
  <p>I tried this code.</p>
  
  <pre><code>$hex = "long_hex_string_not_included_here";
  $hex = str_replace($a,$b,$hex);
  //using this later will produced unwanted extra swaps
  $hex = str_replace($b,$a,$hex);
  </code></pre>
  
  <p>I am looking for a function to swap these values.</p>