PHP/String/str ireplace

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

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

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



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