<?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 => 'ru',
  ),
  'this' => 
  array (
    0 => 'function.strstr.php',
    1 => 'strstr',
    2 => 'Находит первое вхождение подстроки',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'Функции для работы со строками',
  ),
  'prev' => 
  array (
    0 => 'function.strspn.php',
    1 => 'strspn',
  ),
  'next' => 
  array (
    0 => 'function.strtok.php',
    1 => 'strtok',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ru',
    'path' => 'reference/strings/functions/strstr.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.strstr" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">strstr</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">strstr</span> &mdash; <span class="dc-title">Находит первое вхождение подстроки</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.strstr-description">
  <h3 class="title">Описание</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>strstr</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.boolean.php" class="type bool">bool</a></span> <code class="parameter">$before_needle</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>): <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.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   Функция возвращает часть строки <code class="parameter">haystack</code>
   от начала первого вхождения подстроки <code class="parameter">needle</code>
   до конца строки <code class="parameter">haystack</code>.
  </p>
  <blockquote class="note"><p><strong class="note">Замечание</strong>: 
   <p class="para">
    Функция учитывает регистр символов. Для поиска без учёта
    регистра вызывают функцию <span class="function"><a href="function.stristr.php" class="function">stristr()</a></span>.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Замечание</strong>: 
   <p class="para">
    Вместо этой функции вызывают
    функцию <span class="function"><a href="function.str-contains.php" class="function">str_contains()</a></span>,
    которая ищет быстрее и с меньшим потреблением памяти,
    когда требуется только определить, встречается ли
    подстрока <code class="parameter">needle</code> в строке <code class="parameter">haystack</code>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.strstr-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">
 До PHP 8.0.0 нестроковый аргумент <code class="parameter">needle</code>
 преобразовывался в целое число и заменялся на символ с этим порядковым значением в однобайтовой таблице символов.
 Начиная с PHP 7.3.0 передача нестроковых значений устарела и полагаться на него настоятельно не рекомендуют.
 Перед вызовом функции нестроковый аргумент <code class="parameter">needle</code> требовалось
 либо приводить к строке, либо получать строковое значение символа функцией <span class="function"><a href="function.chr.php" class="function">chr()</a></span>.
</p>

     </dd>
    
    
     <dt><code class="parameter">before_needle</code></dt>
     <dd>
      <p class="para">
       Со значением <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> функция <span class="function"><strong>strstr()</strong></span> возвращает
       часть строки <code class="parameter">haystack</code> от начала входной строки
       до первого вхождения подстроки <code class="parameter">needle</code>, не включая «иглу».
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.strstr-returnvalues">
  <h3 class="title">Возвращаемые значения</h3>
  <p class="para">
   Функция возвращает часть строки или <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>,
   если не нашла подстроку <code class="parameter">needle</code>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.strstr-changelog">
  <h3 class="title">Список изменений</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Версия</th>
       <th>Описание</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <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>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.strstr-examples">
  <h3 class="title">Примеры</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Пример #1 Пример поиска первого вхождения подстроки функцией <span class="function"><strong>strstr()</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 /><br />$email  </span><span style="color: #007700">= </span><span style="color: #DD0000">'name@example.com'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$domain </span><span style="color: #007700">= </span><span style="color: #0000BB">strstr</span><span style="color: #007700">(</span><span style="color: #0000BB">$email</span><span style="color: #007700">, </span><span style="color: #DD0000">'@'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$domain</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">; </span><span style="color: #FF8000">// Выводит: @example.com<br /><br /></span><span style="color: #0000BB">$user </span><span style="color: #007700">= </span><span style="color: #0000BB">strstr</span><span style="color: #007700">(</span><span style="color: #0000BB">$email</span><span style="color: #007700">, </span><span style="color: #DD0000">'@'</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">; </span><span style="color: #FF8000">// Выводит: name<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 seealso" id="refsect1-function.strstr-seealso">
  <h3 class="title">Смотрите также</h3>
  <p class="para">
   <ul class="simplelist">
    <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.strrchr.php" class="function" rel="rdfs-seeAlso">strrchr()</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.strpbrk.php" class="function" rel="rdfs-seeAlso">strpbrk()</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); ?>