<?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.stripos.php',
    1 => 'stripos',
    2 => '查找字符串首次出现的位置（不区分大小写）',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => '字符串 函数',
  ),
  'prev' => 
  array (
    0 => 'function.stripcslashes.php',
    1 => 'stripcslashes',
  ),
  'next' => 
  array (
    0 => 'function.stripslashes.php',
    1 => 'stripslashes',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/strings/functions/stripos.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.stripos" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">stripos</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">stripos</span> &mdash; <span class="dc-title">查找字符串首次出现的位置（不区分大小写）</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.stripos-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>stripos</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$haystack</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$needle</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$offset</code><span class="initializer"> = 0</span></span>): <span class="type"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   返回在<span class="type">字符串</span> <code class="parameter">haystack</code> 中 <code class="parameter">needle</code> 首次出现的数字位置。
  </p>
  <p class="para">
   与 <span class="function"><a href="function.strpos.php" class="function">strpos()</a></span> 不同，<span class="function"><strong>stripos()</strong></span> 不区分大小写。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.stripos-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">haystack</code></dt>
     <dd>
      <p class="para">
       在该字符串中查找。
      </p>
     </dd>
    
    
     <dt><code class="parameter">needle</code></dt>
     <dd>
      <p class="para">
       要搜索的字符串。
      </p>
      
 <p class="para">
  Prior to PHP 8.0.0, if <code class="parameter">needle</code> is not a string, it is converted
  to an integer and applied as the ordinal value of a character.
  This behavior is deprecated as of PHP 7.3.0, and relying on it is highly
  discouraged. Depending on the intended behavior, the
  <code class="parameter">needle</code> should either be explicitly cast to string,
  or an explicit call to <span class="function"><a href="function.chr.php" class="function">chr()</a></span> should be performed.
 </p>

     </dd>
    
    
     <dt><code class="parameter">offset</code></dt>
     <dd>
      <p class="para">
       可选的 <code class="parameter">offset</code> 参数，从字符此数量的开始位置进行搜索。
       如果是负数，就从字符末尾此数量的字符数开始统计。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.stripos-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回 needle 存在于 <code class="parameter">haystack</code> 字符串开始的位置(独立于偏移量)。同时注意字符串位置起始于 0，而不是 1。
  </p>
  <p class="para">
   如果未发现 needle 将返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。
  </p>
  <div class="warning"><strong class="warning">警告</strong><p class="simpara">此函数可能返回布尔值
<strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>，但也可能返回等同于 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> 的非布尔值。请阅读 <a href="language.types.boolean.php" class="link">布尔类型</a>章节以获取更多信息。应使用
<a href="language.operators.comparison.php" class="link">===
运算符</a>来测试此函数的返回值。</p></div>
 </div>


 <div class="refsect1 errors" id="refsect1-function.stripos-errors">
  <h3 class="title">错误／异常</h3>
  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     如果 <code class="parameter">offset</code> 大于 <code class="parameter">haystack</code>
     的长度，则会抛出 <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> 异常。
    </span>
   </li>
  </ul>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.stripos-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>


     <tr>
 <td>8.0.0</td>
 <td>
  <code class="parameter">needle</code> 现在接受空字符串。
 </td>
</tr>

      <tr>
       <td>8.0.0</td>
       <td>
        不再支持 <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> 传递给 <code class="parameter">needle</code>。
       </td>
      </tr>

      <tr>
       <td>7.3.0</td>
       <td>
        弃用 <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> 传递给 <code class="parameter">needle</code>。
       </td>
      </tr>

     <tr>
      <td>7.1.0</td>
      <td>
       开始支持负数的 <code class="parameter">offset</code>。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.stripos-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
   <p><strong>示例 #1 <span class="function"><strong>stripos()</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 />$findme    </span><span style="color: #007700">= </span><span style="color: #DD0000">'a'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$mystring1 </span><span style="color: #007700">= </span><span style="color: #DD0000">'xyz'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$mystring2 </span><span style="color: #007700">= </span><span style="color: #DD0000">'ABC'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$pos1 </span><span style="color: #007700">= </span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$mystring1</span><span style="color: #007700">, </span><span style="color: #0000BB">$findme</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$pos2 </span><span style="color: #007700">= </span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$mystring2</span><span style="color: #007700">, </span><span style="color: #0000BB">$findme</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// 'a' 当然不在 'xyz' 中<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$pos1 </span><span style="color: #007700">=== </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"The string '</span><span style="color: #0000BB">$findme</span><span style="color: #DD0000">' was not found in the string '</span><span style="color: #0000BB">$mystring1</span><span style="color: #DD0000">'"</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">// 注意这里使用的是 !==。简单的 != 不能像我们期望的那样工作，<br />// 因为 'a' 的位置是 0（第一个字符）。<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$pos2 </span><span style="color: #007700">!== </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"We found '</span><span style="color: #0000BB">$findme</span><span style="color: #DD0000">' in '</span><span style="color: #0000BB">$mystring2</span><span style="color: #DD0000">' at position </span><span style="color: #0000BB">$pos2</span><span style="color: #DD0000">"</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 notes" id="refsect1-function.stripos-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: <span class="simpara">此函数可安全用于二进制对象。</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.stripos-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.mb-stripos.php" class="function" rel="rdfs-seeAlso">mb_stripos()</a> - 大小写不敏感地查找字符串在另一个字符串中首次出现的位置</span></li>
    <li><span class="function"><a href="function.str-contains.php" class="function" rel="rdfs-seeAlso">str_contains()</a> - 确定字符串是否包含指定子串</span></li>
    <li><span class="function"><a href="function.str-ends-with.php" class="function" rel="rdfs-seeAlso">str_ends_with()</a> - 检查字符串是否以指定子串结尾</span></li>
    <li><span class="function"><a href="function.str-starts-with.php" class="function" rel="rdfs-seeAlso">str_starts_with()</a> - 检查字符串是否以指定子串开头</span></li>
    <li><span class="function"><a href="function.strpos.php" class="function" rel="rdfs-seeAlso">strpos()</a> - 查找字符串首次出现的位置</span></li>
    <li><span class="function"><a href="function.strrpos.php" class="function" rel="rdfs-seeAlso">strrpos()</a> - 计算指定字符串在目标字符串中最后一次出现的位置</span></li>
    <li><span class="function"><a href="function.strripos.php" class="function" rel="rdfs-seeAlso">strripos()</a> - 计算指定字符串在目标字符串中最后一次出现的位置（不区分大小写）</span></li>
    <li><span class="function"><a href="function.stristr.php" class="function" rel="rdfs-seeAlso">stristr()</a> - strstr 函数的忽略大小写版本</span></li>
    <li><span class="function"><a href="function.substr.php" class="function" rel="rdfs-seeAlso">substr()</a> - 返回字符串的子串</span></li>
    <li><span class="function"><a href="function.str-ireplace.php" class="function" rel="rdfs-seeAlso">str_ireplace()</a> - str_replace 的忽略大小写版本</span></li>
   </ul>
  </p>
 </div>


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