1
0
mirror of https://github.com/php/doc-uk.git synced 2026-04-23 14:58:20 +02:00
Files
2014-09-18 10:10:58 +00:00

179 lines
6.0 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 5b39c74139ed16e20f683c6cc5e80c57b9a565ba Maintainer: ktretyak Status: ready -->
<!-- $Revision$ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.strpos">
<refnamediv>
<refname>strpos</refname>
<refpurpose>Знаходить позицію першого входження підрядка в рядку</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>mixed</type><methodname>strpos</methodname>
<methodparam><type>string</type><parameter>haystack</parameter></methodparam>
<methodparam><type>mixed</type><parameter>needle</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>offset</parameter><initializer>0</initializer></methodparam>
</methodsynopsis>
<para>
Знаходить номер позиції першого входження
<parameter>needle</parameter> в рядку <parameter>haystack</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>
Підрядок, який шукається в рядку <parameter>haystack</parameter>.
Якщо параметр <parameter>needle</parameter> не є рядком, він конвертується
в ціле число (integer) та сприймається як порядковий номер (код) символа.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>offset</parameter></term>
<listitem>
<para>
Якщо цей параметр вказано, то пошук почнеться із зазначеної кількості символів
від початку рядка. На відміну від <function>strrpos</function> та
<function>strripos</function>, даний параметр не може бути від'ємним.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Повертає позицію, де знаходиться підрядок, відносно початку
рядка <parameter>haystack</parameter> (незалежно від зміщення offset). Також
зверніть увагу, що позиція підрядка відраховується починаючи від 0, а не від 1.
</para>
<para>
Повертає &false; якщо підрядок не було знайдено.
</para>
&return.falseproblem;
</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' знаходиться в нульовій позиції.
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 != false) оцінюється як хибний.
if ($pos !== false) {
echo "Підрядок '$findme' буде знайдено в рядку '$mystring'";
echo " в позиції $pos";
} else {
echo "Підрядок '$findme' не знайдено в рядку '$mystring'";
}
?>
]]>
</programlisting>
</example>
<example>
<title>Використання зміщення (offset)</title>
<programlisting role="php">
<![CDATA[
<?php
// Ми можемо шукати символи, ігноруючи початкові символи до певного зміщення (offset)
$newstring = 'abcdef abcdef';
$pos = strpos($newstring, 'a', 1); // $pos = 7, не 0
?>
]]>
</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>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
-->