1
0
mirror of https://github.com/php/doc-ru.git synced 2026-04-23 23:38:07 +02:00
Files
Mikhail Alferov 5c2121df00 Update strpos to En (#1124)
* Update mb-stripos.xml to En

* Update mb-stripos.xml

* Update mb-strpos.xml to En

* Update mb-stripos.xml

* Update mb-strpos.xml

* Update mb-stripos.xml

* Update language-snippets.ent Исправил формулировки

* Update mb-strripos.xml to en

* Update mb-strrpos.xml to En

* Update stripos.xml to en

* Update stripos.xml

* Update strpos.xml to en

* Update stripos.xml

* Update strripos.xml to en

* Update language-snippets.ent
2025-10-31 05:38:33 +03:00

235 lines
7.7 KiB
XML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 4b72b23513caa3a8bc520d459a0417defc7b3880 Maintainer: shein Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="function.strpos" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>strpos</refname>
<refpurpose>Ищет позицию первого вхождения подстроки</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type class="union"><type>int</type><type>false</type></type><methodname>strpos</methodname>
<methodparam><type>string</type><parameter>haystack</parameter></methodparam>
<methodparam><type>string</type><parameter>needle</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>offset</parameter><initializer>0</initializer></methodparam>
</methodsynopsis>
<para>
Функция ищет в строке <parameter>haystack</parameter>
позицию первого вхождения подстроки <parameter>needle</parameter>.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>haystack</parameter></term>
<listitem>
<para>
Строка, в которой выполняется поиск.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>needle</parameter></term>
<listitem>
<para>
Строка, которую требуется найти.
</para>
&strings.parameter.needle.non-string;
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>offset</parameter></term>
<listitem>
<para>
При установке параметра функция начнёт поиск с заданного количества символов с начала строки.
При отрицательном значении функция отсчитывает
позицию начала поиска с конца строки.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Функция возвращает позицию искомой подстроки относительно начала строки <parameter>haystack</parameter>
независимо от значения параметра <parameter>offset</parameter>.
Обратите также внимание, что позиция строки отсчитывается с <literal>0</literal>, а не с <literal>1</literal>.
</para>
<para>
Функция возвращает значение &false;, если не нашла строку.
</para>
&return.falseproblem;
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<itemizedlist>
<listitem>
<simpara>
Функция выбросит ошибку <classname>ValueError</classname>,
если значение параметра <parameter>offset</parameter> превысит
длину строки <parameter>haystack</parameter>.
</simpara>
</listitem>
</itemizedlist>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
&strings.changelog.needle-empty;
<row>
<entry>8.0.0</entry>
<entry>
Функция больше не поддерживает передачу целого числа (&integer;) в параметр <parameter>needle</parameter>.
</entry>
</row>
<row>
<entry>7.3.0</entry>
<entry>
Передача целого числа (&integer;) в параметр <parameter>needle</parameter> устарела.
</entry>
</row>
<row>
<entry>7.1.0</entry>
<entry>
Добавили поддержку отрицательных значений параметром <parameter>offset</parameter>.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Пример строго сравнения значений оператором <literal>===</literal></title>
<programlisting role="php">
<![CDATA[
<?php
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
// Обратите внимание, что значения сравниваются оператором ===. Оператор == не будет работать
// как ожидается, поскольку позиция символа «a» — первого по счёту символа — равнялась 0.
if ($pos === false) {
echo "Функция не нашла подстроку «{$findme}» в строке «{$mystring}»";
} else {
echo "Функция нашла подстроку «{$findme}» в строке «{$mystring}»";
echo " в позиции $pos";
}
?>
]]>
</programlisting>
</example>
<example>
<title>Пример проверки результата оператором !==</title>
<programlisting role="php">
<![CDATA[
<?php
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
// Оператором !== тоже проверяют результат поиска позиции подстроки. Оператор != не сработает
// как ожидается, поскольку позиция подстроки 'a' равна 0. Инструкция (0 != false) вычисляется
// как false, поскольку при нестрогом сравнении false неявно приводится к 0
if ($pos !== false) {
echo "Функция нашла подстроку «{$findme}» в строке «{$mystring}»";
echo " в позиции {$pos}";
} else {
echo "Функция не нашла подстроку «{$findme}» в строке «{$mystring}»";
}
?>
]]>
</programlisting>
</example>
<example>
<title>Пример установки смещения</title>
<programlisting role="php">
<![CDATA[
<?php
// Игнорируем символы до значения смещения, а затем находим символ
$newstring = 'abcdef abcdef';
$pos = strpos($newstring, 'a', 1); // Переменная $pos = 7, а не 0
echo $pos, PHP_EOL;
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
&note.bin-safe;
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>stripos</function></member>
<member><function>str_contains</function></member>
<member><function>str_ends_with</function></member>
<member><function>str_starts_with</function></member>
<member><function>strrpos</function></member>
<member><function>strripos</function></member>
<member><function>strstr</function></member>
<member><function>strpbrk</function></member>
<member><function>substr</function></member>
<member><function>preg_match</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->