Use str_replace() with less elements in replace than find in PHP

Description

The following code shows how to use str_replace() with less elements in replace than find.

Example


// w  ww . j a  v a2 s .c  om
<?php
    $find = array("HELLO","WORLD"); // This function is case-insensitive
    $replace = array("B");
    $arr = array("Hello","world","!");
    print_r(str_ireplace($find,$replace,$arr));
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone