• 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 strcmp() – Binary safe string comparison
  2. PHP function abs – Absolute value
  3. PHP function chunk_split() – Split a string into smaller chunks
  4. PHP Function strchr() – Alias of strstr()
  5. PHP function strlen() – Get string length
  6. PHP asin function – Arc sine
  7. PHP decbin function – Decimal to binary
  8. htaccess Cheatsheet
  9. PHP atan function – Arc tangent
  10. PHP bindec function – Convert a number between arbitrary bases

You May Also Like

Primary Sidebar

Recent Posts

  • ctags: Generates an index (or tag) file of language objects found in source files for many popular programming languages
  • csvtool: Utility to filter and extract data from CSV formatted sources
  • csvstat: Print descriptive statistics for all columns in a CSV file
  • csvsql: Generate SQL statements for a CSV file or execute those statements directly on a database

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright