mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-03-29 04:12:21 +02:00
git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@274154 c90b9560-bf6c-de11-be94-00142212c4b1
181 lines
5.0 KiB
XML
181 lines
5.0 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.20 $ -->
|
|
<!-- EN-Revision: 1.18 Maintainer: yannick Status: ready -->
|
|
<!-- Reviewed: yes -->
|
|
|
|
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.strpos">
|
|
<refnamediv>
|
|
<refname>strpos</refname>
|
|
<refpurpose>Trouve la position d'un caractère dans une chaîne</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>int</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>
|
|
Retourne la position numérique de la première occurrence de
|
|
<parameter>needle</parameter> dans la chaîne de caractères
|
|
<parameter>haystack</parameter>. Contrairement à la fonction
|
|
<function>strrpos</function> avant PHP 5, celle-ci peut prendre une chaîne de caractères
|
|
complète comme paramètre <parameter>needle</parameter> et cette chaîne sera
|
|
utilisée en totalité.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>haystack</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
La chaîne dans laquelle on doit chercher.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>needle</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si <parameter>needle</parameter> n'est pas une chaîne, il est
|
|
converti en entier, et utilisé comme caractère de code ASCII
|
|
correspondant.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>offset</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Le paramètre optionnel <parameter>offset</parameter> vous permet
|
|
de spécifier à partir de quel caractère dans <parameter>haystack</parameter>
|
|
vous souhaitez commencer la recherche. La position retournée sera toujours
|
|
relative au début de la chaîne <parameter>haystack</parameter>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Retourne la position, sous la forme d'un &integer;. Si
|
|
<parameter>needle</parameter> n'est pas trouvé,
|
|
<function>strpos</function> retournera &false;.
|
|
</para>
|
|
&return.falseproblem;
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Avec ===</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$mystring = 'abc';
|
|
$findme = 'a';
|
|
$pos = strpos($mystring, $findme);
|
|
|
|
// Notez notre utilisation de ===. == ne fonctionnerait pas comme attendu
|
|
// car la position de 'a' est la 0-ième (premier) caractère.
|
|
if ($pos === false) {
|
|
echo "La chaîne '$findme' ne se trouve pas dans la chaîne '$mystring'";
|
|
} else {
|
|
echo "La chaine '$findme' a été trouvée dans la chaîne '$mystring'";
|
|
echo " et débute à la position $pos";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
|
|
<example>
|
|
<title>Avec !==</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$mystring = 'abc';
|
|
$findme = 'a';
|
|
$pos = strpos($mystring, $findme);
|
|
|
|
// Notez notre utilisation de !==. != ne fonctionnerait pas comme attendu
|
|
// car la position de 'a' est la 0-ième (premier) caractère.
|
|
if ($pos !== false) {
|
|
echo "La chaine '$findme' a été trouvée dans la chaîne '$mystring'";
|
|
echo " et débute à la position $pos";
|
|
} else {
|
|
echo "La chaîne '$findme' ne se trouve pas dans la chaîne '$mystring'";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
|
|
<example>
|
|
<title>Utiliser un offset</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// Nous pouvons chercher le caractère, et ignorer tout ce qui est avant l'offset
|
|
$newstring = 'abcdef abcdef';
|
|
$pos = strpos($newstring, 'a', 1); // $pos = 7, non pas 0
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
¬e.bin-safe;
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>strrpos</function></member>
|
|
<member><function>stripos</function></member>
|
|
<member><function>strripos</function></member>
|
|
<member><function>strrchr</function></member>
|
|
<member><function>substr</function></member>
|
|
<member><function>stristr</function></member>
|
|
<member><function>strstr</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:"../../../../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
|
|
-->
|