<?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-starts-with.php',
    1 => 'str_starts_with',
    2 => '检查字符串是否以指定子串开头',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => '字符串 函数',
  ),
  'prev' => 
  array (
    0 => 'function.str-split.php',
    1 => 'str_split',
  ),
  'next' => 
  array (
    0 => 'function.str-word-count.php',
    1 => 'str_word_count',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/strings/functions/str-starts-with.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.str-starts-with" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">str_starts_with</h1>
  <p class="verinfo">(PHP 8)</p><p class="refpurpose"><span class="refname">str_starts_with</span> &mdash; <span class="dc-title">检查字符串是否以指定子串开头</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.str-starts-with-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>str_starts_with</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="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   执行大小写区分的检查，表明 <code class="parameter">haystack</code> 是否以 <code class="parameter">needle</code> 开头。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.str-starts-with-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">
       要在 <code class="parameter">haystack</code> 中搜索的子串。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.str-starts-with-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   如果 <code class="parameter">haystack</code> 以 <code class="parameter">needle</code> 开头，返回 <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>，否则返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.str-starts-with-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 使用空字符串 <code class="literal">&#039;&#039;</code></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">str_starts_with</span><span style="color: #007700">(</span><span style="color: #DD0000">'abc'</span><span style="color: #007700">, </span><span style="color: #DD0000">''</span><span style="color: #007700">)) {<br />    echo </span><span style="color: #DD0000">"All strings start with the empty string"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>以上示例会输出：</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">All strings start with the empty string</pre>
</div>
    </div>
   </div>

   <div class="example" id="example-2">
    <p><strong>示例 #2 展示大小写区分</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$string </span><span style="color: #007700">= </span><span style="color: #DD0000">'The lazy fox jumped over the fence'</span><span style="color: #007700">;<br /><br />if (</span><span style="color: #0000BB">str_starts_with</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">, </span><span style="color: #DD0000">'The'</span><span style="color: #007700">)) {<br />    echo </span><span style="color: #DD0000">"The string starts with 'The'\n"</span><span style="color: #007700">;<br />}<br /><br />if (</span><span style="color: #0000BB">str_starts_with</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">, </span><span style="color: #DD0000">'the'</span><span style="color: #007700">)) {<br />    echo </span><span style="color: #DD0000">'The string starts with "the"'</span><span style="color: #007700">;<br />} else {<br />    echo </span><span style="color: #DD0000">'"the" was not found because the case does not match'</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>以上示例会输出：</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">The string starts with &#039;The&#039;
&quot;the&quot; was not found because the case does not match</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.str-starts-with-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.str-starts-with-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <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.stripos.php" class="function" rel="rdfs-seeAlso">stripos()</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.strstr.php" class="function" rel="rdfs-seeAlso">strstr()</a> - 查找字符串的首次出现</span></li>
    <li><span class="function"><a href="function.strpbrk.php" class="function" rel="rdfs-seeAlso">strpbrk()</a> - 在字符串中查找一组字符的任何一个字符</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.preg-match.php" class="function" rel="rdfs-seeAlso">preg_match()</a> - 执行匹配正则表达式</span></li>
   </ul>
  </p>
 </div>


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