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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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 strcasecmp() – Binary safe case-insensitive string comparison
  2. PHP function convert_cyr_string() – Convert from one Cyrillic character set to another
  3. PHP function chr() – Generate a single-byte string from a number
  4. PHP function chop() – Alias of rtrim()
  5. PHP function strcmp() – Binary safe string comparison
  6. PHP Function strchr() – Alias of strstr()
  7. How to test a PHP script
  8. PHP function stripcslashes() – Un-quote string quoted with addcslashes()
  9. PHP ceil function – Round fractions up
  10. PHP atan2 function – Arc tangent of two variables

You May Also Like

Primary Sidebar

Recent Posts

  • fprintd-delete Command Examples in Linux
  • fprintd-delete: command not found
  • foreman: command not found
  • foreman Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright