<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.strings.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.str-ireplace.php',
    1 => 'str_ireplace',
    2 => 'str_replace 的忽略大小写版本',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => '字符串 函数',
  ),
  'prev' => 
  array (
    0 => 'function.str-increment.php',
    1 => 'str_increment',
  ),
  'next' => 
  array (
    0 => 'function.str-pad.php',
    1 => 'str_pad',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/strings/functions/str-ireplace.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.str-ireplace" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">str_ireplace</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">str_ireplace</span> &mdash; <span class="dc-title"><span class="function"><a href="function.str-replace.php" class="function">str_replace()</a></span> 的忽略大小写版本</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.str-ireplace-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>str_ireplace</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$search</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$replace</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.array.php" class="type array">array</a></span></span> <code class="parameter">$subject</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter reference">&$count</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span><br>): <span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.array.php" class="type array">array</a></span></span></div>

  <p class="para rdfs-comment">
   该函数返回字符串或者数组。该字符串或数组是将 <code class="parameter">subject</code> 中全部的 <code class="parameter">search</code> 都被 <code class="parameter">replace</code> 替换（忽略大小写）之后的结果。
  </p>
  <p class="para">
   要根据模式而不是固定字符串替换文本，将 <span class="function"><a href="function.preg-replace.php" class="function">preg_replace()</a></span> 与 <code class="literal">i</code> <a href="reference.pcre.pattern.modifiers.php" class="link">模式修饰符</a>一起使用。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.str-ireplace-parameters">
  <h3 class="title">参数</h3>
  
  <p class="para">
   如果 <code class="parameter">search</code> 和 <code class="parameter">replace</code> 为数组，那么 <span class="function"><strong>str_ireplace()</strong></span> 将对 <code class="parameter">subject</code> 做二者的映射替换。如果 <code class="parameter">replace</code> 的值的个数少于 <code class="parameter">search</code> 的个数，多余的替换将使用空字符串来进行。如果 <code class="parameter">search</code> 是一个数组而 <code class="parameter">replace</code> 是一个字符串，那么 <code class="parameter">search</code> 中每个元素的替换将始终使用这个字符串。
  </p>
  <p class="para">
   如果 <code class="parameter">search</code> 或 <code class="parameter">replace</code> 是数组，他们的元素将从头到尾一个个处理。
  </p>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">search</code></dt>
     <dd>
       <p class="para">
        要搜索的值，就像是 <em>needle</em>。可以使用 array 来提供多个 needle。
       </p>
     </dd>
    
    
     <dt><code class="parameter">replace</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">search</code> 的替换值。一个数组可以被用来指定多重替换。
      </p>
     </dd>
    
    
     <dt><code class="parameter">subject</code></dt>
     <dd>
      <p class="para">
       要被搜索和替换的字符串或数组，就像是
      <em>haystack</em>。
      </p>
      <p class="para">
       如果 <code class="parameter">subject</code> 是一个数组，替换操作将遍历整个 <code class="parameter">subject</code>，并且也将返回一个数组。
      </p>
     </dd>
    
    
     <dt><code class="parameter">count</code></dt>
     <dd>
      <p class="para">
      如果被指定，它的值将被设置为替换发生的次数。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.str-ireplace-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回替换后的字符串或者数组。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.str-ireplace-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     
 <tr>
  <td>8.2.0</td>
  <td>
   大小写转换不在依赖于使用 <span class="function"><a href="function.setlocale.php" class="function">setlocale()</a></span> 设置的区域。只会进行 ASCII
   大小写转换。非 ASCII 字节值将通过它们的字节值进行比较。
  </td>
 </tr>


    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.str-ireplace-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="function"><strong>str_ireplace()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?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">"&lt;body text=%BODY%&gt;"</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$bodytag</span><span style="color: #007700">; </span><span style="color: #FF8000">// &lt;body text=black&gt;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.str-ireplace-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: <span class="simpara">此函数可安全用于二进制对象。</span></p></blockquote>
  <div class="caution"><strong class="caution">警告</strong>
   <h1 class="title">替换顺序陷阱</h1>
   <p class="para">
    因为 <span class="function"><strong>str_ireplace()</strong></span> 是从左到右替换，当进行多个替换时，可能会替换先前插入的值。<span class="function"><a href="function.str-replace.php" class="function">str_replace()</a></span>
    文档中的示例 #2 展示了在实践中受到的影响。
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.str-ireplace-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.str-replace.php" class="function" rel="rdfs-seeAlso">str_replace()</a> - 子字符串替换</span></li>
    <li><span class="function"><a href="function.preg-replace.php" class="function" rel="rdfs-seeAlso">preg_replace()</a> - 执行一个正则表达式的搜索和替换</span></li>
    <li><span class="function"><a href="function.strtr.php" class="function" rel="rdfs-seeAlso">strtr()</a> - 转换字符或替换字串</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>