PHP/String/str ireplace

Материал из Web эксперт
Перейти к: навигация, поиск

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

   <source lang="html4strict">

<?

   $string = "this is a TEST";
   $newstring = str_ireplace("TEST", "test", $string);
   print $newstring;

?>

 </source>
   
  


Implementing a phrase-substitution algorithm

   <source lang="html4strict">

<?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);

?>

 </source>