Implementing a phrase-substitution algorithm : str_ireplace « String « PHP






Implementing a phrase-substitution algorithm

 
<?php
  $codebook = array(
    'A' => 'a',
    'sun' => 'frog',
    'rises' => 'jumps'
  );
  $message = 'The sun rises.';
  $encoded_message = str_ireplace(array_keys($codebook), array_values($codebook),
                                  $message);
  $decoded_message = str_ireplace(array_values($codebook), array_keys($codebook),
                                  $encoded_message);
?>
  
  








Related examples in the same category

1.Case-insensitive version of str_replace( ): str_ireplace( )