<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Case-insensitive version of str_replace</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.str-getcsv.html">str_getcsv</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.str-pad.html">str_pad</a></div> <div class="up"><a href="ref.strings.html">String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.str-ireplace" class="refentry"> <div class="refnamediv"> <h1 class="refname">str_ireplace</h1> <p class="verinfo">(PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">str_ireplace</span> — <span class="dc-title">Case-insensitive version of <span class="function"><a href="function.str-replace.html" class="function">str_replace()</a></span></span></p> </div> <div class="refsect1 description" id="refsect1-function.str-ireplace-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>str_ireplace</strong></span> ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$search</code></span> , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$replace</code></span> , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$subject</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$count</code></span> ] )</div> <p class="para rdfs-comment"> This function returns a string or an array with all occurrences of <code class="parameter">search</code> in <code class="parameter">subject</code> (ignoring case) replaced with the given <code class="parameter">replace</code> value. If you don't need fancy replacing rules, you should generally use this function instead of <span class="function"><a href="function.preg-replace.html" class="function">preg_replace()</a></span> with the <em>i</em> modifier. </p> </div> <div class="refsect1 parameters" id="refsect1-function.str-ireplace-parameters"> <h3 class="title">Parameters</h3> <p class="para"> If <code class="parameter">search</code> and <code class="parameter">replace</code> are arrays, then <span class="function"><strong>str_ireplace()</strong></span> takes a value from each array and uses them to search and replace on <code class="parameter">subject</code>. If <code class="parameter">replace</code> has fewer values than <code class="parameter">search</code>, then an empty string is used for the rest of replacement values. If <code class="parameter">search</code> is an array and <code class="parameter">replace</code> is a string, then this replacement string is used for every value of <code class="parameter">search</code>. The converse would not make sense, though. </p> <p class="para"> If <code class="parameter">search</code> or <code class="parameter">replace</code> are arrays, their elements are processed first to last. </p> <p class="para"> <dl> <dt> <code class="parameter">search</code></dt> <dd> <p class="para"> The value being searched for, otherwise known as the <em class="emphasis">needle</em>. An array may be used to designate multiple needles. </p> </dd> <dt> <code class="parameter">replace</code></dt> <dd> <p class="para"> The replacement value that replaces found <code class="parameter">search</code> values. An array may be used to designate multiple replacements. </p> </dd> <dt> <code class="parameter">subject</code></dt> <dd> <p class="para"> The string or array being searched and replaced on, otherwise known as the <em class="emphasis">haystack</em>. </p> <p class="para"> If <code class="parameter">subject</code> is an array, then the search and replace is performed with every entry of <code class="parameter">subject</code>, and the return value is an array as well. </p> </dd> <dt> <code class="parameter">count</code></dt> <dd> <p class="para"> If passed, this will be set to the number of replacements performed. </p> </dd> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.str-ireplace-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns a string or an array of replacements. </p> </div> <div class="refsect1 examples" id="refsect1-function.str-ireplace-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="similar_text.example.swapping"> <p><strong>Example #1 <span class="function"><strong>str_ireplace()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$bodytag </span><span style="color: #007700">= </span><span style="color: #0000BB">str_ireplace</span><span style="color: #007700">(</span><span style="color: #DD0000">"%body%"</span><span style="color: #007700">, </span><span style="color: #DD0000">"black"</span><span style="color: #007700">, </span><span style="color: #DD0000">"<body text=%BODY%>"</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$bodytag</span><span style="color: #007700">; </span><span style="color: #FF8000">// <body text=black><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.str-ireplace-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">This function is binary-safe.</span></p></blockquote> <div class="caution"><strong class="caution">Caution</strong> <h1 class="title">Replacement order gotcha</h1> <p class="para"> Because <span class="function"><strong>str_ireplace()</strong></span> replaces left to right, it might replace a previously inserted value when doing multiple replacements. Example #2 in the <span class="function"><a href="function.str-replace.html" class="function">str_replace()</a></span> documentation demonstrates how this may affect you in practice. </p> </div> </div> <div class="refsect1 seealso" id="refsect1-function.str-ireplace-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><span class="function"><a href="function.str-replace.html" class="function" rel="rdfs-seeAlso">str_replace()</a> - Replace all occurrences of the search string with the replacement string</span></li> <li class="member"><span class="function"><a href="function.preg-replace.html" class="function" rel="rdfs-seeAlso">preg_replace()</a> - Perform a regular expression search and replace</span></li> <li class="member"><span class="function"><a href="function.strtr.html" class="function" rel="rdfs-seeAlso">strtr()</a> - Translate characters or replace substrings</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.str-getcsv.html">str_getcsv</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.str-pad.html">str_pad</a></div> <div class="up"><a href="ref.strings.html">String Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>