• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

PHP function str_ireplace() – Case-insensitive version of str_replace()

by admin

The str_ireplace() function is used to replace some case insensitive characters in a string. This function was introduced in PHP5. Performs a case-insensitive search for all occurrences of search in string and replaces them with replace. If all three parameters are strings, a string is returned. If string is an array, the replacement is performed for every element in the array and an array of results is returned. If search and replace are both arrays, elements in search are replaced with the elements in replace with the same numeric indices. Finally, if search is an array and replace is a string, any occurrence of any element in search is changed to replace. If supplied, count is filled with the number of instances replaced.

Syntax:

str_ireplace(
    array|string $search,
    array|string $replace,
    string|array $subject,
    int &$count = null
): string|array

Parameters

Parameter Description
search The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles.
replace The replacement value that replaces found search values. An array may be used to designate multiple replacements.
subject The string or array being searched and replaced on, otherwise known as the haystack.
count If passed, this will be set to the number of replacements performed.

Return Values

Returns a string or an array of replacements.

Example

Example 1:

<?php
$bdtag = str_ireplace(“%bd%”, “blue”, “<body text=%BD%>”);
?>

Example 2:

$string = "Adam went home";
$newstring = str_ireplace("adam", "John", $string);
print $newstring;

With that code, $newstring will be printed out as “John went home”. So it ignores the “A” in “Adam” as capital letter.

Example 3:

<?php
$bodytag = str_ireplace("%body%", "black", "");
echo $bodytag; // 
?>

Filed Under: PHP

Some more articles you might also be interested in …

  1. PHP function stripslashes() – Un-quotes a quoted string
  2. PHP connection_status function – Returns connection status bitfield
  3. PHP ceil function – Round fractions up
  4. PHP base_convert function – Convert a number between arbitrary bases
  5. PHP atan function – Arc tangent
  6. PHP function strlen() – Get string length
  7. PHP function str_replace() – Replace all occurrences of the search string with the replacement string
  8. PHP function chunk_split() – Split a string into smaller chunks
  9. How to test a PHP script
  10. PHP function chr() – Generate a single-byte string from a number

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright